views:

990

answers:

3

I have an HttpHandler that is run on a client page (cross domain, not on our IIS server, etc) and when they click on our embedded link it fires off the Handler on our server. So far everything is working normally.

I am now trying to use the System.Web.HttpContext.Session object but it is null. I am thinking it is null because we don't have a session until our HttpHandler is invoked? And multiple calls to the handler will create a new session per call? If this is the case did MS just disable the Session object when calling into a HttpHandler? Can anyone confirm this?

If this is the case, what do you do to maintain state between calls? Some sort of SQL based data object? A file?

TIA

+4  A: 

I think you have to implement the empty interface IReadOnlySessionState, so the context will be loaded.

edit to add:

According to Michael Morton's answer, you can also implement IRequiresSessionState, which will give you write access also to the Session object

Jhonny D. Cano -Leftware-
+7  A: 

Have your HttpHandler inherit from IRequiresSessionState. It will enable session state use.

Michael Morton
+1 mmm i didn't knew that one, i love S.O.
Jhonny D. Cano -Leftware-
A: 

try using the current context...

System.Web.HttpContext.Current.Session
Joe Davis
doesn't work, unless he implements one of the both marker interfaces
Jhonny D. Cano -Leftware-
Session will be null without IRequiresSessionState / IReadOnlySessionState
Colin
My bad... was thinking of HttpModules.
Joe Davis