我想知道是否有办法实现像http://www.mycompany.com/user这样的url在MVC中 我尝试使用 catch all,但无法让用户通过,因此我可以进行查找。
谢谢
最佳答案
类似这样的吗?
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 = "" }
);
关于asp.net-mvc - URL 路由 捕获所有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1160643/