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.



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.

Leave a Reply