For MVC 5, probably 4 as well, RouteConfig is now where the default route is defined. Before matching the default routes, I had several calls to "routes.IgnoreRoute", and here is one example:
routes.IgnoreRoute("{*changeaccount}", new { changeaccount = @"(.*/)?change.account(/.*)?" }); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );
Now, when I added the settings area to the site, navigated to the URL that would hit the action in that area, and then tried to switch to change.account, my ignore route call in RouteConfig no longer blocked this call from being submitted to the routing mechanism.
After reading this post and looking at other places, I realized that I can essentially have the same route as in the SettingsAreaConfiguration.cs file, with the slight difference that the Routes live as the AreaRegistrationContext property.
public override void RegisterArea(AreaRegistrationContext context) { context.Routes.IgnoreRoute("{*changeaccount}", new { changeaccount = @"(.*/)?change.account(/.*)?" }); context.MapRoute( "Settings_default", "Settings/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); }
And wow! The problem is solved!
Now I had quite a few IgnoreRoute calls, so I copied all those calls that were standard on my site to a new extension method that extends RouteCollection.
public static class RouteCollectionExtensions { public static void IgnoreRoutesCommon(this RouteCollection routes) { routes.IgnoreRoute("{*changeaccount}", new { changeaccount = @"(.*/)?change.account(/.*)?" }); } }
I can add more IgnoreRoute calls inside this method, now that I have a central place to store all these calls.
Now I can replace the specific IgnoreRoute call for "change.account" with a call to my extension method.
Thus, the call in the RouteConfig.cs file will look like this:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoutesForCommon(); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
And the call in the SettingsAreaConfiguration.cs file will look like this:
public override void RegisterArea(AreaRegistrationContext context) { context.Routes.IgnoreRoutesForCommon(); context.MapRoute( "Settings_default", "Settings/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); }
Suh-Weet !: O)