<p>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?</p>

<p>The routing code in global.asax:</p>

<pre><code>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 = "" }  
        );

    }
</code></pre>

<p>Thanks!</p>

[{'answer_id': 70396, 'author': 'Steve Morgan', 'author_id': 5806, 'author_profile': 'https://Stackoverflow.com/users/5806', 'pm_score': 4, 'selected': True, 'text': '<p>I\'d suggest adding an explicit route for /Pages/ at the beginning.</p>\n\n<p>The problem is that it\'s being handled by the Default route and deriving:</p>\n\n<p>controller = "Pages"\naction = "Index"\nid = ""</p>\n\n<p>which are exactly the same as the parameters for your Admin route.</p>\n'}, {'answer_id': 70481, 'author': 'Garry Shutler', 'author_id': 6369, 'author_profile': 'https://Stackoverflow.com/users/6369', 'pm_score': 2, 'selected': False, 'text': '<p>You could add a constraint to the default rule so that the {Controller} tag cannot be "Pages".</p>\n'}, {'answer_id': 80676, 'author': 'Hrvoje Hudo', 'author_id': 1407, 'author_profile': 'https://Stackoverflow.com/users/1407', 'pm_score': 0, 'selected': False, 'text': '<p>You have in you first route {action} token/parameter which gets in conflict with setting of default action. Try changing parameter name in your route, or remove default action name.</p>\n'}, {'answer_id': 93920, 'author': 'Haacked', 'author_id': 598, 'author_profile': 'https://Stackoverflow.com/users/598', 'pm_score': 3, 'selected': False, 'text': '<p>For routing issues like this, you should try out my <a href="http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx" rel="noreferrer">Route Debugger</a> assembly (use only in testing). It can help figure out these types of issues.</p>\n\n<p>P.S. If you\'re trying to secure the Pages controller, make sure to use the [Authorize] attribute. Don\'t just rely on URL authorization.</p>\n'}]
['https://Stackoverflow.com/questions/70371', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11334/']