I have a problem on a page if the session expires. I think I can solve the problem with code that tests for a new session: -
Dim NewSession As Boolean
Dim httpApplication As New HttpApplication
If httpApplication.Session.IsNewSession = True Then
NewSession = True
Else
NewSession = False
End If
If Not Page.IsPostBack OrElse NewSession = True Then
' do first time code .....
This should execute my first-time code when the session has expired, as well as a genuine Not Postback.
How do I test this with Visual Studio? I read somewhere that VS debugger sessions don't expire, so unless I use the production environment for testing (obviously not a good idea) I can't just start a test and wait 20 minutes.
Dim NewSession As Boolean = False
If Not Page.IsPostBack Then
Session("Table_aspx_session") = "Exists"
ElseIf IsNothing(Session("Table_aspx_session")) Then
NewSession = True ' It must have timed out
End If
It was safe enough, so I tested in on the production site. The name of the session variable, "Table_aspx_session" ensures that it is unique to this page which is table.aspx.
Marked as answer by Robert Barnes on Apr 04, 2012 03:38 AM
Robert Barne...
Member
451 Points
708 Posts
How do I test my session-expiry code with VS2010
Apr 03, 2012 11:31 PM|LINK
I have a problem on a page if the session expires. I think I can solve the problem with code that tests for a new session: -
Dim NewSession As Boolean
Dim httpApplication As New HttpApplication
If httpApplication.Session.IsNewSession = True Then
NewSession = True
Else
NewSession = False
End If
If Not Page.IsPostBack OrElse NewSession = True Then
' do first time code .....
This should execute my first-time code when the session has expired, as well as a genuine Not Postback.
How do I test this with Visual Studio? I read somewhere that VS debugger sessions don't expire, so unless I use the production environment for testing (obviously not a good idea) I can't just start a test and wait 20 minutes.
Thank you, Robert.
Robert Barne...
Member
451 Points
708 Posts
Re: How do I test my session-expiry code with VS2010
Apr 04, 2012 01:48 AM|LINK
Correction, my code doesn't work. The statement
If httpApplication.Session.IsNewSession = True Then ...
thows an error:
Session state is not available in the current context
Robert Barne...
Member
451 Points
708 Posts
Re: How do I test my session-expiry code with VS2010
Apr 04, 2012 03:38 AM|LINK
This worked.
Dim NewSession As Boolean = False
If Not Page.IsPostBack Then
Session("Table_aspx_session") = "Exists"
ElseIf IsNothing(Session("Table_aspx_session")) Then
NewSession = True ' It must have timed out
End If
It was safe enough, so I tested in on the production site. The name of the session variable, "Table_aspx_session" ensures that it is unique to this page which is table.aspx.