saving session state in an http module

I finally have a Web project that demands the use of the cooler features of ASP.NET. One of these features is tracking which search engine a visitor was referred by and storing that info. in a Session variable. This is a perfect reason to use an HTTP module.
There's plenty of code (most of it copied from MSDN) regarding creating a module and subscribing to the HttpApplication event you want and doing something when that event fires. Unfortunately, the information on what the events do leaves a little to be desired.
My dilema was that I needed to find which event would allow me to write to the Sesssion state. At first, I used BeginRequest and got a nice error that SessionState wasn't available in that context. Damn, now I had to read the descriptions of what each event does. I'd like to say I decoded the meanings and chose the correct event but I used a little deductive reasoning and trial and error instead.
PreSendRequestHeaders – nope
ReleaseRequestState – nope
AcquireRequestState – bingo!
That's the one that worked and allowed writing to the Session state.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s