I have the following in my RouteConfig.cs file
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
// route default URL to index.aspx
routes.MapPageRoute(
routeName: "LoginPageRoute",
routeUrl: "login",
physicalFile: "~/Login.aspx"
);
routes.MapPageRoute("LoginPageRoute2", "login2", "~/Login.aspx");
}
However if I try to access my WebApp using "login" or "login2" I get a resource cannot be found error message.
- http://localhost:4200/login2 - fails
- http://localhost:4200/login - fails
- http://localhost:4200/Login.aspx - loads fine
My Global.asax has the following
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
A comment from somebody under my question guided me to the solution which was to move my custom routes ahead of the default routes.
Adding the following to Global.asax helped prove that this was indeed the issue.
Putting a breakpoint on
Showed that my "login" mapping was using the default route mapping instead of my custom route mapping.
Thanks again @mason!