ASP.NET MVC WebAPI 404 error

前端 未结 8 1446
一生所求
一生所求 2020-12-13 23:31

I have an asp.net web forms application running under v4.0 integrated mode.

I tried to add an apicontroller in the App_Code folder.

In the Global.asax, I ad

相关标签:
8条回答
  • 2020-12-14 00:33

    Thanks Shannon, works great =>

    My order in my Global.asax was :

    GlobalConfiguration.Configure(WebApiConfig.Register);  
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    

    instead of the good one :

    RouteConfig.RegisterRoutes(RouteTable.Routes);
    GlobalConfiguration.Configure(WebApiConfig.Register); 
    
    0 讨论(0)
  • 2020-12-14 00:35

    I was experiencing this problem.

    I tried editing my WebApiConfig.cs to meet a number of recommendations here and code samples elsewhere. Some worked, but it didn't explain to why the route was not working when WebApiConfig.cs was coded exactly as per the MS template WebApi project.

    My actual problem was that in manually adding WebApi to my project, I had not followed the stock order of configuration calls from Global.asax

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            // This is where it "should" be
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            // The WebApi routes cannot be initialized here.
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    

    I could make guesses about why this is, but I didn't investigate further. It wasn't intuitive to say the least.

    0 讨论(0)
提交回复
热议问题