Do WebApi 2 and MVC 5 API users have different routing attributes?

Reading through this blog post about attribute routing in ASP.NET MVC 5 and this in attribute routing in Web Api 2, it looks like there are two sets of routing attributes, one in the System.Web.Mvc and the other in System.Web.Http .

  • Is it right, and does anyone have any ideas (links) regarding why it was designed in this way?
  • Should one or the other be used, or should they live side by side?
+7
asp.net-mvc-5 asp.net-web-api2 asp.net-routing
source share
1 answer
  • Yes, these route attributes are intentionally different because the web APIs and MVCs have different (but similar) routing systems.
  • Use MVC RouteAttribute for MVC controllers / actions. Use Web RouteATtribute (System.Web.Http) for web API controllers / actions. If you use one that does not match, it most likely will not work.
+5
source share

All Articles