I don't want to use ASP.NET MVC WebApi, but I do want to use the URL /api/controller/action so that it is handled by my own controller
I'm doing this:
routes.MapRoute(
name: "APIRoute",
url: "api/{controller}/{action}/",
namespaces: new[] { "MyProject.Controllers.APIControllers" }
But it seems that is not possible to use api/
in MapRoute(...)
If I navigate to http://localhost/api/Blah/List
it doesn't work
If I change the route to this:
routes.MapRoute(
name: "APIRoute",
url: "apix/{controller}/{action}/",
namespaces: new[] { "MyProject.Controllers.APIControllers" }
(Notice the 'x' in 'apix/')
And then I navigate to http://localhost/apix/Blah/List
it works as expected
What can I do? is it possible to override api/
?
Sounds like you may have created a new project which includes Web API which is why you're having a hard time.
Search your project for
WebApiConfig
orDefaultApi
- if you have any results then Web API has been added to your project and you'll want to amend the defaultrouteTemplate
which is by defaultapi/{controller}/{id}
.