1

在 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 });
4

1 回答 1

0

尝试编写自定义路由处理程序:http: //geekswithblogs.net/sankarsan/archive/2009/01/18/developing-custom-routehandler.aspx

于 2013-01-20T05:19:30.217 回答