在 ASP.NET MVC4 Web API 中,我想支持一种 url:
api/{part1}/{part2}/{id}
其控制器是 {part1}{part2},例如
url controller class
api/ch01/products/ ch01products ch01productscontroller
api/ch12/customers ch12customers ch12customerscontroller
api/books/page/5 bookspage bookspagecontroller
我可以在 MapHttpRoute 中执行此操作吗?就像是
// in WebApiConfig.Register
config.Routes.MapHttpRoute("", "api/{part1}/{part2}/{id}", new { controller = ? "{part1}" + "{part2}" ?, id = RouteParameter.Optional });