我正在尝试按照ASP.NET OutputCache and Cookies
中的建议在Global.asax.vb中的Application_EndRequest中设置一个cookie我编写了以下代码,cookie获取ERROR
值。
为什么没有会话?
Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim context As HttpContext = HttpContext.Current
If Not context.Session Is Nothing Then
context.Response.Cookies("T").Value = context.Session("T")
Else
context.Response.Cookies("T").Value = "ERROR"
End If
End Sub
答案 0 :(得分:13)
Application_EndRequest
事件中的会话不再存在。
Application_PostRequestHandlerExecute
被释放之前,会调用 SessionState
。
Sub Application_PostRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
Dim context As HttpContext = HttpContext.Current
If Not context.Session Is Nothing Then
context.Response.Cookies("T").Value = context.Session("T")
Else
context.Response.Cookies("T").Value = "ERROR"
End If
End Sub