主要是實現Web Api Attribute路由的功能 對應的還有 Mvc 版。 AttributeRouting for GitHubhtml
參考(不是很好): http://www.cnblogs.com/n-pei/archive/2012/07/17/2595352.htmlgit
安裝github
Install-Package AttributeRouting.WebApi
[Get("Link")]web
http://localhost:0001/link getapi
[Get("Link/Oschina")]asp.net
http://localhost:0001/Link/Oschina getpost
[Post("LinkPost")].net
http://localhost:0001/link postcode
[Put("LinkPost")]htm
http://localhost:0001/link put
是否是超級方便
安裝
Install-Package Microsoft.AspNet.WebApi.WebHost
配置 (MVC 在 RouteConfig.cs | Web Api 在 WebApiConfig.cs)
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); routes.MapRoute( ... ); }
[HttpGet]
[Route("Link/{customerId}/orders")]
http://localhost:0001/link/{customerId}/orders get
[HttpDelete]
[Route("Orders/Delete/{id}")]
http://localhost:0001/Orders/Delete/{id} delete
必定要參考內容
http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api
謝謝