这样做的WebAPI 2和MVC 5用户不同的路由属性? [英] Do WebApi 2 and MVC 5 user different routing attributes?
本文介绍了这样做的WebAPI 2和MVC 5用户不同的路由属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到<一读href=\"http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx\">this博客文章的属性在ASP.NET MVC 5和路由<一个href=\"http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2\">this一个在属性在网页API 2路由,它看起来像有两套路由属性,一个在 System.Web.Mvc
命名空间和其他在 System.Web.Http
。
- 是正确的,并没有任何人有任何想法(链接),为什么它是这样设计?
- 如果有一个比其他使用或者他们应该并排?共处
解决方案
- 是的,这些路由属性是故意不同,因为网络API和MVC具有不同(但相近)路由系统
- 使用MVC RouteAttribute MVC的控制器/行动。使用基于Web API控制器/行动的Web API RouteATtribute(System.Web.Http)。如果你使用一个不匹配,可能只是将无法工作。
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
.
- Is that right and does anyone have any idea (links) as to why it was designed this way?
- Should one be used over the other or are they supposed to live side by side?
解决方案
- Yes, these route attributes are intentionally different since Web API and MVC have distinct (but similar) routing systems
- 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.
这篇关于这样做的WebAPI 2和MVC 5用户不同的路由属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文