开发者

SessionState not being preserved in Handlers [duplicate]

This question already has answers here: Closed 11 years ago.

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 Sessi开发者_如何学编程on 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?


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

public sealed class MyHandler : IHttpHandler, IReadOnlySessionState {


Not sure if yours is a IHttpHandler or a IHttpModule since you used both terms.

For Handlers, if you need Session available you also need to implement IRequireSessionState.

If you want to access session state in your HttpModule be sure to add your EventHandler to the HttpApplications PreRequestHandlerExecute” event, NOT the “BeginRequest” event.

Also look at Can I access session state from an HTTPModule?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜