Context.Session object is null in Application_AcquireRequestState

早过忘川 提交于 2019-12-23 12:42:25

问题


I upgraded my website from .NET 1.1 to .NET 4.0. In my Global.asax.vb file I'm trying to access the Context.Session object in the Application_AcquireRequestState method and I am getting a null reference exception when I first attempt to access the website.

I installed the .NET 4.0 version of the website on a different test server using IIS 7.5 and everything seemed to work OK. But when I install the .NET 4.0 version of the website on the original server that uses IIS 6 I'm getting the exception.

Any idea why I am getting this exception? Do the different versions of IIS handle the HTTP Pipeline events differently? Or is there a difference from when the Session object becomes available between the two .NET versions I'm using?

Any help would be appreciate, thank you!!


回答1:


You should use Application_PreRequestHandlerExecute instead of Application_AcquireRequestState

I just fixed same problem, but for c#, translating code it must be something like that:

Private Sub Application_PreRequestHandlerExecute(sender As Object, e As EventArgs)
If TypeOf Context.Handler Is IRequiresSessionState OrElse TypeOf Context.Handler Is IReadOnlySessionState Then
    ' HttpContext.Current.Session should be available
End If
End Sub


来源:https://stackoverflow.com/questions/10195791/context-session-object-is-null-in-application-acquirerequeststate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!