问题描述
我升级我的网站从.NET 1.1到.NET 4.0。在我的 Global.asax.vb
文件我试图访问在<$ c中的 Context.Session
对象$ C> Application_AcquireRequestState
方法和我得到一个空引用异常,当我第一次尝试访问该网站。
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.
我安装使用IIS 7.5不同的测试服务器上的.NET 4.0版本的网站,一切似乎工作确定。但是,当我安装.NET 4.0版本的网站,它使用原始服务器上IIS 6,我发现了异常。
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.
任何想法,为什么我得到这个例外?别不同版本的IIS处理HTTP管道事件不同?还是有距离的时候Session对象变成我使用?
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?
任何帮助将是AP preciate,谢谢!
Any help would be appreciate, thank you!!
推荐答案
您应该使用 Application_ preRequestHandlerExecute
而不是 Application_AcquireRequestState
我只是固定的同样的问题,但对于C#,翻译code它必须是类似的东西:
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
这篇关于Context.Session对象是Application_AcquireRequestState空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!