tags:

views:

518

answers:

2

I am trying to set Session values using a IHttpModule. I have set the HttpModule to be used for all requests, not just managed/ASPX pages.

I found however, that when a request for a non-ASP.NET page came in (such as gif) the Session member of the HttpApplication would throw an exception or be null.

I found the following SO post for the reason behind this: link

When I am swapping out the HttpHandler with one that implements IRequiresSessionState the Session member is available in the HttpModule, and a Set-Cookie is sent back to the browser, but later when I try to read the contents of the session in a normal ASPX page none of the values I set are there. When debugging I can see that the SessionID is the same in both the HttpModule and normal ASPX page.

Do I need to do anything to force the session to be saved? I am assuming that while swapping in the fake HttpHandler initialises the Session, having to put the original which doesn't implement IRequiresSessionState back in causes the session to not be saved at the end of the request.

+1  A: 

I just worked it out, I had to move the re-mapping of the original HttpHandler from PostAcquireRequestState to PreRequestHandlerExecute.

Paul
A: 

Here is a nice explanation on this problem:

How to access Session values from my custom HttpHandler in ASP.NET?

Roboblob