ASP.NET MVC 4 ApiController and Normal Controller Routes

后端 未结 1 927
谎友^
谎友^ 2021-01-19 02:33

I have a project that is used solely for API requests into our app and we are using an ASP.NET MVC 4 project. We have some Controllers that derive from the ApiController an

相关标签:
1条回答
  • 2021-01-19 03:01

    The only way this can be done from what I can see is to explicitly name each API controller. Below I have a SomeApiController class.

    routes.MapHttpRoute(
        name: "SomeApiController",
        routeTemplate: "SomeApi/{action}/{id}",
        defaults: new { controller = "SomeApi", id = RouteParameter.Optional }
    );
    
    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    
    0 讨论(0)
提交回复
热议问题