Why is HttpContext.Current.Session available in HttpModule but not in Response.Filter?

I wrote an HttpModule that adds a response filter. The filter captures the output of the page and stores it in the session variable.

  • I can access the HttpContext.Current.Session in my HttpModule.
  • The HttpModule handles the PostAcquireRequestState event.
  • I can still access the HttpContext.Current.Session in the PostAcquireRequestState event.
  • In the PostAcquireRequestState event, I add my own stream, which inherits from Stream to Response.Filter
  • HttpContext.Current.Session is null when accessing the Stream.Write method.

Everything worked perfectly when using InProc SessionState. However, now I have to use StateServer. Using StateServer, the code is now broken.

Any ideas?

+4
source share
1 answer

Have you tried passing the session object from your HttpModule to your filter constructor and thus preserving the link?

Usually I will never rely on access to HttpContext.Current in my filters, but I pass the necessary values ​​through the constructor or setting some properties before assigning Response.Filter. This separates things and makes them more convenient.

0
source

Source: https://habr.com/ru/post/1305699/


All Articles