Search code examples
c#asp.netsession-state

SessionState not being preserved in Handlers


Possible Duplicate:
Can I access session state from an HTTPModule?

I have set up and am using SQLServer State handling and it works well within my project. But I have shared resource file that provides handlers for loading images form the database, etc. In this module, the Session is always Null. I have tried the following:

  1. Full path for Session variable i.e., HttpContext.Current.Session["varname"];
  2. I have added the sessionState line to the web.config for the user controls file that has the handlers, just like I did for the main project.

Is there anything else to make session variables available in a module? I am relatively new to .net so I may have used the incorrect terminology. The be clear, I have a 'Solution' defined. In this solution is a 'Project' called CMS. There are also two other projects in the solution - one for handling shared classes and one for handlers. These external files are included by reference in the main Project (of course, or it wouldn't work at all). It is in these 'external' projects that I cannot seem to be able to access the Session variables.

Any help is greatly appreciated. O, and while I am fine with RTFM type responses, previous questions I have asked point me to long, theoretical MSDN documents that rarely help because they are too deep for my comprehension. Try to give a brother a break huh?


Solution

  • You need to use either the IReadOnlySessionState or the IRequiresSessionState interface in the class declaration, like this:

    public sealed class MyHandler : IHttpHandler, IReadOnlySessionState {