ASP.NET MVC Route Debugging

When working with Routes in ASP.NET MVC, you sometimes expect a route to match, but another route matches instead. There is currently no way to debug this using Visual Studio.

Phil Haack, from Haacked.com, developed a small utility which displays the route data pulled from the request of the current request in the address bar.  At the bottom, it shows a list of all defined routes in your application. This allows you to see which of your routes would match the current URL.

route-tester-windows-internet-explorer-2_3

All you need to do to start debugging your routes is add Phil Haack’s assembly to your bin folder and add one simple line to your Global.asax:

protected void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
    RouteDebug.RouteDebugger.
        RewriteRoutesForTesting(RouteTable.Routes);
}

You can find Phil’s post here, along with the assembly and even the source code with a demonstration.

This entry was posted on Tuesday, May 26th, 2009 at 8:25 pm and is filed under ASP.NET, C#.NET, Developement, MVC. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply