【问题标题】:MVC3 Dynamic routing multiple urls to single controllerMVC3动态路由多个url到单个控制器
【发布时间】:2012-03-29 22:36:52
【问题描述】:
基本上,我希望实现以下目标:
website.com/{customerName}/SingleController/actions/
SingleController 是一个控制器,它根据对 {customerName} 的数据库查找来提供页面,例如,可能会交换 CSS 文件或其他东西。如何设置将 {customerName} 映射为通配符的路线?首先没有控制器可能看起来倒退,但此设置的主要原因是让客户的不同页面显示在
http://website.com/{customerName}。
【问题讨论】:
标签:
asp.net-mvc-3
c#-4.0
asp.net-mvc-routing
【解决方案1】:
使用注册路由封装的典型示例:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
null, // Route name
"{customerName}/SingleController/actions", // URL with parameters
new { controller = "SingleController", action = "actions" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}