首先,您必须使用 MapRoute 到 MapPageRoute,因为 MapPageRoute 是(来自msdn):
提供一种为 Web 窗体应用程序定义路由的方法
但是,如果您像这样修改代码:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("AccountRoute", "{Action}", new {controller = "Account"});
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
每个没有参数的请求都将转到 AccountRoute,即使它应该由其他控制器处理。
唯一可行的方法是创建如下代码:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//ALL routes you need
routes.MapRoute("LoginRoute", "{Action}", new { controller = "Account", action = "Login" });
routes.MapRoute("RegisterRoute", "{Action}", new { controller = "Account", action = "Register" });
//Default route in the end
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);