Chapter 24. Debugging routes
This chapter covers
- Customizing the routing system
- Inspecting route matches
In chapter 16, you learned all about routing, so you probably already understand that routing is a complex and important topic. What happens when routing doesn’t behave the way we expect?
In this chapter, we’ll extend the routing system to provide diagnostic information about which routes are being matched for a given web request.
The UrlRoutingModule is an implementation of IHttpModule and represents the entry point into the ASP.NET MVC Framework. This module examines each request, builds up the RouteData for the request, finds an appropriate IRouteHandler for the given route matched, and finally redirects the request to the IRouteHandler’s IHttpHandler.
In any ASP.NET MVC application, the default route looks like the one in listing 24.1. The MapRoute method is a simplified way of specifying routes.
Most of the applications you’ll work with will use this style of adding routes. There’s also a more verbose method, which allows us to customize the classes that are used as part of the route. Listing 24.2 shows the same route but without using the MapRoute helper method.