UPDATES:
- Updated and simplified sample project.
- Updated original post with IIS7 example here.
- You can see a sample site running here.  As it’s using IIS6 I needed to add a Wildcard Application Mapping.  Note this passes every request through ASP.NET; you might prefer some alternative options, or use IIS 7 where you get it for free.
- Updated sample and overview of using SiteMaps with routing here.

Since my earlier post on using the System.Web.Routing assembly with traditional WebForms (here), I’ve had some requests for a sample project to show it in action.  You can get the source right here.

This sample shows a way of getting the route information from the RouteHandler to the page, with minimal changes to existing pages (good if you’re migrating from a 3rd party URL rewriter).  Basically the WebFormRouteHandler copies relevant routing values into the HttpContext.Items collection (so they’ll only exist for the lifetime of the current request).  You can then grab these values in your WebForm.

For another example of passing routing details to a WebForm, see Phil Haack’s great post here.

About these ads