何时在ASP.NET管道中初始化会话状态

时间:2020-12-17 03:30:08

I have an IHTTPModule with an event handler for AuthorizeRequest. I would like to access the Session object but it is not yet initialized. Which event should I subscribe to in order to have the session object available as early as possible in the pipeline?

我有一个带有AuthorizeRequest事件处理程序的IHTTPModule。我想访问Session对象但它尚未初始化。我应该订阅哪个事件,以便尽早在管道中提供会话对象?

1 个解决方案

#1


7  

You needd HttpApplication.PostAcquireRequestState event - http://msdn.microsoft.com/en-us/library/system.web.httpapplication.postacquirerequeststate.aspx. Also there is a HttpApplication.AcquireRequestState event. Don't forget to check if your handler implements IRequiresSessionState or IReadOnlySessionState, otherwise it will throw an exception.

您需要HttpApplication.PostAcquireRequestState事件 - http://msdn.microsoft.com/en-us/library/system.web.httpapplication.postacquirerequeststate.aspx。还有一个HttpApplication.AcquireRequestState事件。不要忘记检查您的处理程序是否实现IRequiresSessionState或IReadOnlySessionState,否则它将引发异常。

#1


7  

You needd HttpApplication.PostAcquireRequestState event - http://msdn.microsoft.com/en-us/library/system.web.httpapplication.postacquirerequeststate.aspx. Also there is a HttpApplication.AcquireRequestState event. Don't forget to check if your handler implements IRequiresSessionState or IReadOnlySessionState, otherwise it will throw an exception.

您需要HttpApplication.PostAcquireRequestState事件 - http://msdn.microsoft.com/en-us/library/system.web.httpapplication.postacquirerequeststate.aspx。还有一个HttpApplication.AcquireRequestState事件。不要忘记检查您的处理程序是否实现IRequiresSessionState或IReadOnlySessionState,否则它将引发异常。