我正在尝试让 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。有人知道我缺少什么吗?