I am building my site using Asp.Net Webpages 2 and Razor (C#).
I tried to insert WebApi controller and all I get is 404. Controller is a default one.
I even tried adding
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
and I still get 404.
What else is there to do ?
I did it. In Global.asax you need to add
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.Web.Http" %>
And in Application_Start
RouteTable.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } );
Now it is working like it should. It did not work before because I tried the same code in Global.asax.cs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With