Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net MVC 5.0注册表端口不工作_Asp.net_Asp.net Mvc_Asp.net Mvc 5 - Fatal编程技术网

Asp.net MVC 5.0注册表端口不工作

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",

任何人都知道为什么这不起作用,我已经在谷歌上搜索过了,但似乎什么都不起作用。我想做的就是允许www.abcdefg.com/username映射到个人资料页面,但它不起作用,我也不知道为什么

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的字符串参数?