Do WebApi 2 and MVC 5 user different routing attributes?
Asked Answered
B

1

7

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

  1. Is that right and does anyone have any idea (links) as to why it was designed this way?
  2. Should one be used over the other or are they supposed to live side by side?
Brody answered 12/11, 2013 at 18:5 Comment(0)
S
5
  1. Yes, these route attributes are intentionally different since Web API and MVC have distinct (but similar) routing systems
  2. Use the MVC RouteAttribute on MVC controllers/actions. Use the Web API RouteATtribute (System.Web.Http) on Web API controllers/actions. If you use one that doesn't match, it likely just won't work.
Shirl answered 14/11, 2013 at 0:46 Comment(3)
Do you happen to have a reference for them having different routing systems?Brody
Well, I'm on the product team and have worked on both routing systems; does that count? :) Also, see asp.net/web-api/overview/web-api-routing-and-actions/…Shirl
That does indeed count, I guess I was also hoping for more of an explanation of why, but the part at the top of the article you linked to about using HTTP method for routing sort of addresses that.Brody

© 2022 - 2024 — McMap. All rights reserved.