I’m trying out ASP.NET MVC routing and have of course stumbled across a problem. I have a section, /Admin/Pages/, and this is also accessible through /Pages/, which it shouldn’t. What could I be missing?
The routing code in global.asax:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute('{resource}.axd/{*pathInfo}'); routes.MapRoute( 'Pages', // Route name 'Admin/Pages/{action}/{id}', // URL with parameters // Parameter defaults new { controller = 'Pages', action = 'Index', id = '' } ); routes.MapRoute( 'Default', // Route name '{controller}/{action}/{id}', // URL with parameters // Parameter defaults new { controller = 'Home', action = 'Index', id = '' } ); }
Thanks!
I’d suggest adding an explicit route for /Pages/ at the beginning.
The problem is that it’s being handled by the Default route and deriving:
controller = ‘Pages’ action = ‘Index’ id = ”
which are exactly the same as the parameters for your Admin route.