ASP.NET MVC WebAPI 404 error

前端 未结 8 1472
一生所求
一生所求 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:17

    The problem is in your routing configuration. Mvc routing is different from WebApi routing.

    Add reference to System.Web.Http.dll, System.Web.Http.Webhost.dll and System.Net.Http.dll and then configure your API routing as follows:

       GlobalConfiguration.Configuration.Routes.MapHttpRoute(
         name: "DefaultApi",
         routeTemplate: "api/{controller}/{id}",
         defaults: new { id = System.Web.Http.RouteParameter.Optional }
       );
    

提交回复
热议问题