R
ronchese
I'm noticing this since I started developing a website project: my session variables are getting empty!
I did a real easy test, and I checked my session variable is getting empty!! What is happening?
For example (VS2005, IE6/7, running in filesystem):
- In the Page_load of page1.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Throw New Exception("Error is thrown")
End Sub
- Then, I catch this on global.asax:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'get current context
Dim ctxContext As HttpContext = HttpContext.Current
If ctxContext Is Nothing Then Exit Sub
'get last error
Dim ex As Exception = ctxContext.Server.GetLastError()
Session("LastException") = ex.Message
'redict to error page
Response.Redirect("../Other/ErrorPage.aspx")
End Sub
- Finally, in the errorpage.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblMessage.Text = Session("LastException") '<-- The session is empty!!
End Sub
There are other situations the same problems also appear. For example, I'm setting an object to session via a shared class and when I gonna get that object again, its empty. In question of less a minute!
Is there any issue with session variables happening in .NET?
Cesar
I did a real easy test, and I checked my session variable is getting empty!! What is happening?
For example (VS2005, IE6/7, running in filesystem):
- In the Page_load of page1.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Throw New Exception("Error is thrown")
End Sub
- Then, I catch this on global.asax:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'get current context
Dim ctxContext As HttpContext = HttpContext.Current
If ctxContext Is Nothing Then Exit Sub
'get last error
Dim ex As Exception = ctxContext.Server.GetLastError()
Session("LastException") = ex.Message
'redict to error page
Response.Redirect("../Other/ErrorPage.aspx")
End Sub
- Finally, in the errorpage.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblMessage.Text = Session("LastException") '<-- The session is empty!!
End Sub
There are other situations the same problems also appear. For example, I'm setting an object to session via a shared class and when I gonna get that object again, its empty. In question of less a minute!
Is there any issue with session variables happening in .NET?
Cesar