Asp.net MVC 5.0注册表端口不工作
任何人都知道为什么这不起作用,我已经在谷歌上搜索过了,但似乎什么都不起作用。我想做的就是允许www.abcdefg.com/username映射到个人资料页面,但它不起作用,我也不知道为什么Asp.net MVC 5.0注册表端口不工作,asp.net,asp.net-mvc,asp.net-mvc-5,Asp.net,Asp.net Mvc,Asp.net Mvc 5,任何人都知道为什么这不起作用,我已经在谷歌上搜索过了,但似乎什么都不起作用。我想做的就是允许www.abcdefg.com/username映射到个人资料页面,但它不起作用,我也不知道为什么 public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "Default",
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
, new { controller = @"(admin|help|profile|Settings)" } // Constraints
);
routes.MapRoute(
"Users",
"{username}",
new { controller = "Home", action = "Index", username = "" });
}
您必须将默认路由添加为最后一条路由
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Users",
"{username}",
new { controller = "Home", action = "Index", username = "" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
, new { controller = @"(admin|help|profile|Settings)" } // Constraints
);
您是否测试过localhost/Home/Index/username是否有效?我将从这个开始。换句话说,在controller Home中是否有一个名为Index的控制器操作,它接受标记为username的字符串参数?