Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Custom GET Method - No action was found on the controller

$
0
0

Hello There

Issue: When I run the API for GET method which was custom created then I get the above error. Please have look at the RouteConfig and WebApiConfig file

Note: I have created an Area and have made config in a way that both area and normal controller be browsed.

//WebApiConfig
public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{area}/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            //Custom Hippo 
            config.Routes.MapHttpRoute(
                name: "Custom",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

    
        }

//RouteConfig
public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },

                //Area
                namespaces: new string[] { "WebAPI.Areas.Finance.Controllers","WebAPI.Areas.Housing.Controllers"}

            );
        }

Area Registeration

public class FinanceAreaRegistration : AreaRegistration 
    {
        public override string AreaName 
        {
            get 
            {
                return "Funeral";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "Finance_default","Finance/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                new string[] { typeof(Controllers.FinanceController).Namespace, typeof(Controllers.TestController).Namespace } 
              //added even premium controller reg here
            );
        }
    }

I have attrbutted the Get Method as 

 [Route("api/Finance/Premium/{id}")]
        [HttpGet]
        public HttpResponseMessage GetProduct(int prod)
        {

..........
return Request.CreateResponse(HttpStatusCode.OK, res);
          

        }

Please advise


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>