Do WebApi 2 and MVC 5 user different routing attributes?

↘锁芯ラ 提交于 2019-12-22 05:16:31

问题


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?

回答1:


  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.


来源:https://stackoverflow.com/questions/19936647/do-webapi-2-and-mvc-5-user-different-routing-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!