Accessing Session from inside a HTTPHandler

Here something I didn’t know before. By default, you cannot access the session from within an Asp.Net HttpHandler. To be able to do that, your handler class has to implement an extra interface:

System.Web.SessionState.IRequiresSessionState

So, the declaration of your class looks like this:

Code Snippet

If you don’t do this, and try to access Session object from within the Handler code, then you will get an Null Object Reference exception. It didn’t take long to find out that it was the session which was giving the null exception, however it wasn’t intuitive.

If you found this content helpful, then please help by linking to me. You can also help me by sharing the content using any of these nifty buttons above. Thank you.



You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “Accessing Session from inside a HTTPHandler”

  1. Would have wasted a lot of time figuring this out if it weren’t for your post. :)

    Thanks a lot

    Reply
  2. not very helpfull. same problem exists by implementing as described.

    Reply




Leave a Reply