.Net Page Routing Without Global.asax

.Net Page Routing Without Global.asax

I found myself recently needing to get rid of the Global.asax file.  In building a CDN for myself, having a global.asax file forces cookies to be sent with requests, and for the static content I am serving through my CDN, this is a no-no

So what to do?  I still need to do some page routing for a URL shortening service that is tied directly into this cdn (o7t.in is a shor url =))

The answer was pretty much staring me in the face, I just did not realize it, for about 2 days staring at it.   The answer is to use an HTTPModule that imports System.Web, and System.Web.Routing.   Right inside the Init() event is where you would do all your Application_Start stuff!

Just make sure to double check that you do not already have a named route in the collection, because an HTTPModule checks every single request, and the Init() Event fires each time.   (It’s really simple to check…)

If RouteTable.Routes IsNot Nothing AndAlso Not (RouteTable.Routes.Count > 0) Then
    'Register your routes here!
End If

That;s all for now, happy coding!

Kevin Pirnie
22 Years of PC and server maintenance & over 17 years of web development/design experience; you can rest assured that I take every measure possible to ensure your computers are running to their peak potentials. I treat them as if they were mine, and I am quite a stickler about keeping my machines up to date and optimized to run as well as they can.