Application_EndRequest does not find a session

I am trying to set a cookie in Application_EndRequest in Global.asax.vb as suggested here

I wrote the following code, the cookie gets the value ERROR . Why is the session unavailable?

 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 
+8
session global-asax
source share
1 answer

The session no longer exists in the Application_EndRequest event.

Application_PostRequestHandlerExecute is called after the code from your application is executed, but before the SessionState released.

 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 
+11
source share

All Articles