我想知道是否还有在MVC中获得类似http://www.mycompany.com/user的网址 我尝试使用catch all,但无法让用户通过,所以我可以查看。
由于
答案 0 :(得分:1)
这样的东西?
routes.MapRoute("User",
"{UserName}",
new { Controller = "User", Action = "Index", UserName = "" });
<强>更新:强>
将此约束添加到“用户”路线:
routes.MapRoute("User",
"{UserName}",
new { Controller = "User", Action = "Index", UserName = "" },
new { UserName = @"(\w|-)+" }
);
或添加此路线:
routes.MapRoute("Home",
String.Empty,
new { Controller = "Home", Action = "Index", Id = "" }
);