【发布时间】:2013-05-01 00:44:22
【问题描述】:
我正在尝试让 Uri 路径扩展映射在 Web API 中工作。我的路线设置正确:
routes.MapHttpRoute(
name: "Api with extension",
routeTemplate: "api/{controller}.{ext}/{id}",
defaults: new { id = RouteParameter.Optional, ext = RouteParameter.Optional }
);
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
它适用于默认路由,例如/api/products.json/123 但对于其他方法,例如/api/products.json?categoryid=5我收到一条错误消息:
"No action was found on the controller 'Products' that matches the request."
所有路由工作都没有扩展名,例如/api/products/123 和 /api/products?categoryid=5。有人知道我缺少什么吗?
【问题讨论】:
-
请您发布映射这两条路线的操作?
-
它们会映射到:GetProduct(int id) 和 GetProductsByCategory(int categoryid)
标签: .net routes asp.net-mvc-4 asp.net-web-api