为什么http默认路由不包含{action} ?

本文关键字:action 包含 http 默认 路由 为什么 | 更新日期: 2023-09-27 18:06:41

为什么默认的Web Api 2 http路由不包含{action}:

来自microsoft示例:

// Configure Web API for self-host. 
HttpConfiguration config = new HttpConfiguration(); 
config.Routes.MapHttpRoute( 
    name: "DefaultApi", 
    routeTemplate: "api/{controller}/{id}", 
    defaults: new { id = RouteParameter.Optional } 
); 

为什么不是这样呢?

// Configure Web API for self-host. 
HttpConfiguration config = new HttpConfiguration(); 
config.Routes.MapHttpRoute( 
    name: "DefaultApi", 
    routeTemplate: "api/{controller}/{action}/{id}", 
    defaults: new { id = RouteParameter.Optional } 
); 

为什么正确路由不需要动作部分?

代码来自http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api

非常感谢!

为什么http默认路由不包含{action} ?

示例中的操作是隐式匹配的。如果你仔细看,它们都是不同的HTTP动词