I’ve updated my ASP.NET 3.5 + System.Web.Routing sample based on some great feedback and questions.  It’s much simpler and gives a better example of how routes can be configured.  It now uses Phil Haack’s excellent WebFormRouteHandler class, which is much more versatile than my unnecessarily generic one :)

You can run the sample here and grab the source code here and on CodePlex (I love the fact it supports SVN now).

The sample pages derive from a custom ‘RoutablePage’ class, but that’s not mandatory.  For simple routing, you can just derive from Page as usual.

If you’d like to use RequestContext’s GetVirtualPath method (to automatically build URLs based on defined routes) your page can implement IRoutablePage (or derive from RoutablePage which includes some useful helper methods).

About these ads