Starting with this entry I am adding a Talking Points session to our blog intended to give you… Talking Points on a particular topic with an easy to read bulletized approach accompanied (if/when available) with a link to a video from channel-9 or some other Microsoft resource – including links to other blogs.
So today I am going to touch on the new enabling feature of the ASP.NET MVC: ASP.NET Routing.
ASP.NET Routing
This capability is at the heart of a new approach that makes possible the Model-View-Controller pattern for new web applications.
With routing your web application’s URL interface becomes more important. End-users are becoming more competent and expect to see more intuitive patterns that can be manually navigated. With the new ASP.NET Routing engine, you can define a set of routes for your application that map to resources and remove the need to develop URL rewriting logic.
These routes can be used to address any ASP.NET resources, including: WebForms, ASMX services, Dynamic Data, and MVC.
Routing Taxonomy
There are two fundamental concepts that are the basics for ASP.NET Routing: Route, and Route Table/Route Collection. They enable mapping to resources and the generation of URLs
Route:
A Route represents a container for all the metadata/information the routing engine needs to determine whether it satisfies an incoming request. This includes the following:
For the most part you can get away with using the provided Route class to represent your routes, but if you need to extend your routes, you can either inherit from Route, or RouteBase (which is the lowest common denominator).
Because the route is responsible for determining whether it matches the current request, if you wanted to modify the logic that made that determination, you would probably want to create your own route type.
Route Table/Route Collection
At the center of the routing engine is the RouteTable class. This class serves as the repository of your application’s route definitions. It itself contains no functionality, it is simply a container that houses a common RouteCollection, that is exposed through its static Routes property.
The RouteCollection in turns is a list of all routes that have been defined. The RouteCollection implements a composite pattern style where it implement similar functionality as the routes it contains, so that you can perform operations on the collection that are then delegated to each contained route (i.e. URL generation, route matching).
Routing offers two powerful mechanisms:
1. Route to resource mapping
2. URL generation
Pipeline
A pipeline represents the lifecycle of a request in terms of how ASP.NET Routing will process it:
To Learn More about ASP.NET Routing check Scott Guthrie’s detailed blog entry. And to see ASP.NET MVC in action watch our own Marc’s developer dinner webcast.
And remember, ASP.NET MVC is *not* a replacement for ASP.NET Web apps, rather it builds on it to offer this new pattern. Check it out!
Joel Reyes