IHttpModule Over Global.asax

I had the job of re-writing some old code that existed in Global.asax which is used to respond to certain initialisation and tear-down events. A significant event of ours is the Session_Start event as this is where we assign session variables used for the lifetime of the transactions carried out by the user. It’s quite common practise as I have seen and is extremely handy in the context of our application.

The re-write was basically to move some code to a more secure location within a compiled stored procedure on our SQL server (later versions of SQL provide some handy features). I first researched any improvements upon Global.asax as it has been around for so long and had been superseded by its predecessor, Global.asa. IHttpModule was a major hit and seemed to be specifically designed for the purposes of improving upon Global.asax. VB.NET isn’t quite as savvy as registering event listeners in comparison to other popular languages such as C#.NET or Java so that was the first major hurdle I had to get over (which took quite some time, MSDN isn’t the best search tool ;) ). Unfortunately upon further coding I came to realise that the Session_Start event which was freely available – and worked perfectly in Global.asax – firstly didn’t even exist, and secondly required some hacks to ensure that the relative code was called at that specific point in the initialisation of the web session. The solutions I saw just weren’t worth it to be honest.

If you’re looking to ensure that certain code is called on Session_Start then I’d highly advise just sticking with Global.asax. If you don’t require Session_Start and Session_End then it’s definitely worth looking at implementing the IHttpModule interface. Registering the class in your Web.Config allows it to respond to the relative events that are setup to respond to within the implementation. It’s basically a modularised solution to Global.asax. Anyway, I thought this may be a handy bit of knowledge to save you a few hours of tedious work :)

About Kieran

A twenty-four year old software developer from Guernsey, Channel Islands.
This entry was posted in Pages. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>