【发布时间】:2017-05-01 16:12:49
【问题描述】:
我正在尝试更改我的 asp.net 项目的路由。我希望登录控制器在我的项目启动时加载,而不是任何其他控制器。 所以,我在 asp 项目的现有路由中添加了 LoginDefault 路由映射
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "LoginDefault",
url: "{controller}/{action}",
defaults: new { controller = "UserManagement", action = "Login" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
这会正确加载登录控制器,但这样做不会执行默认路由。登录后,仪表板控制器被调用,但“索引”被添加到每个 URL,如下所示。
http://localhost:49799/Dashboard/Index
这影响了我的 URL 和其他 Ajax 调用,这看起来不太整洁。在添加 LoginDefault 之前,URL 将是
http://localhost:49799/Dashboard
我想实现这一目标。如果有任何其他方式是可能的,那也很好。
谢谢
【问题讨论】:
标签: c# asp.net custom-routes