开发者

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

I have written an HttpModule that adds a response filter. The filter is capturing page output and storing it in a session variable.

  1. I am able to access HttpContext.Current.Session in my HttpModule.
  2. The HttpModule is handling the PostAcquireRequestState event.
  3. I am still able to access HttpContext.Current.Session in the PostAcquireRequestState event.
  4. In the PostAcquireRequestState event, I add a custom stream that inherits from Stream to Response.Fi开发者_JAVA百科lter
  5. HttpContext.Current.Session is null when accessed from the Stream.Write method.

Everything worked fine when using an InProc SessionState. However, I now must use StateServer. Using StateServer, the code is now broken.

Any ideas?


Have you tried passing the session-object from your HttpModule to your filters constructor and that way hold a reference?

Normally i would never rely on accessing HttpContext.Current in my filters, but pass the necessary values via constructor or setting some Properties before assigning it to Response.Filter. It decouples things and make it more maintainable.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜