Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 从url中隐藏控制器名称_Asp.net Mvc_Url_Routes - Fatal编程技术网

Asp.net mvc 从url中隐藏控制器名称

Asp.net mvc 从url中隐藏控制器名称,asp.net-mvc,url,routes,Asp.net Mvc,Url,Routes,我想从url中隐藏控制器名称,并执行我正在执行的操作 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "AccountRoute", "{action}", new { controller =

我想从url中隐藏控制器名称,并执行我正在执行的操作

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "AccountRoute",
        "{action}",
        new { controller = "Account", action = "Index" }
        );


        routes.MapRoute(
           "Default", // Route name
           "{controller}/{action}/{id}", // URL with parameters
           new { controller = "Home", action = "Index", id = UrlParameter.Optional }// Parameter defaults
       );

    }
但是当我想去的时候

localhost:1234/设置-不工作

但是

localhost:1234/Account/Settings-works

关于这一点有很多问题,所有这些问题都暗示了我上面已经提到的。
我哪里做错了??还是我遗漏了什么?

尝试向AccountRoute添加可选参数。请注意,您的操作与控制器的名称不同,否则路由将无法正常工作

routes.MapRoute(
    "AccountRoute",
    "{action}/{id}",
    new { controller = "Account", action = "Index", id = UrlParameter.Optional }
);

将您的
AccountRoute
移动到
默认路径下方。请记住,创建这样的路由可能会导致意外后果。

在您的帐户控制器和其他控制器中使用相同名称的操作。只需对命名保持警惕,并了解哪条路由将接收请求。让多人处理一个项目时很重要。好的。我现在明白了。顺便说一下,将“accountroute”移动到“default”下并没有解决它。@GvM如果我们的用户区域具有默认的帐户控制器路由,该怎么办?工具您可能必须检查帐户控制器是否位于正确/预期的命名空间中。