How to handle Invalid Session State on callback
-
I have a page that performs a callback and I'm trying to handle the situation where the session has expired, but the callback is still being invoked. I'm using the following code in my Global.asax
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim httpApp As HttpApplication = Context.ApplicationInstance Dim httpEx As HttpException = httpApp.Server.GetLastError If (httpEx IsNot Nothing) Then If (httpEx.WebEventCode = System.Web.Management.WebEventCodes.AuditInvalidViewStateFailure Or \_ httpEx.WebEventCode = System.Web.Management.WebEventCodes.InvalidViewState Or \_ httpEx.WebEventCode = System.Web.Management.WebEventCodes.InvalidViewStateMac Or \_ httpEx.WebEventCode = System.Web.Management.WebEventCodes.RuntimeErrorViewStateFailure) Then HttpContext.Current.ClearError() Response.Redirect("~/MyErrorPage.aspx", True) End If End If End Sub
The problem is that it is not redirecting to my error page. I'm testing this out on an IIS7 server and I force the error by stopping, then restarting the application pool on the server in between requests. Maybe I'm performing the wrong type of test. Shouldn't this re-direction work? Am I performing the correct type of test ? Ugh. :confused:
-
I have a page that performs a callback and I'm trying to handle the situation where the session has expired, but the callback is still being invoked. I'm using the following code in my Global.asax
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim httpApp As HttpApplication = Context.ApplicationInstance Dim httpEx As HttpException = httpApp.Server.GetLastError If (httpEx IsNot Nothing) Then If (httpEx.WebEventCode = System.Web.Management.WebEventCodes.AuditInvalidViewStateFailure Or \_ httpEx.WebEventCode = System.Web.Management.WebEventCodes.InvalidViewState Or \_ httpEx.WebEventCode = System.Web.Management.WebEventCodes.InvalidViewStateMac Or \_ httpEx.WebEventCode = System.Web.Management.WebEventCodes.RuntimeErrorViewStateFailure) Then HttpContext.Current.ClearError() Response.Redirect("~/MyErrorPage.aspx", True) End If End If End Sub
The problem is that it is not redirecting to my error page. I'm testing this out on an IIS7 server and I force the error by stopping, then restarting the application pool on the server in between requests. Maybe I'm performing the wrong type of test. Shouldn't this re-direction work? Am I performing the correct type of test ? Ugh. :confused:
The fact that your session is went done will not stop the web page to work perfectly correct! ViewState and all the related info was posted to the client (in hidden fields) and will be reused on the next post-back. The only problem with session down is authentication and data you stored on the session (ASP.NET engine do not store nothing on the session by default)... More! You are using down-casting here which can be very dangerous...Who told you GetLastError will return an HttpException! Maybe it's a SystemException or a plain Exception?! Also, if you read explanations of the error codes you use, you will see that none of them is connected to session end - http://msdn.microsoft.com/en-us/library/system.web.management.webeventcodes(v=vs.110).aspx[^] If you want to catch session end - and maybe set a flag for later use - see for Globla.asax...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
The fact that your session is went done will not stop the web page to work perfectly correct! ViewState and all the related info was posted to the client (in hidden fields) and will be reused on the next post-back. The only problem with session down is authentication and data you stored on the session (ASP.NET engine do not store nothing on the session by default)... More! You are using down-casting here which can be very dangerous...Who told you GetLastError will return an HttpException! Maybe it's a SystemException or a plain Exception?! Also, if you read explanations of the error codes you use, you will see that none of them is connected to session end - http://msdn.microsoft.com/en-us/library/system.web.management.webeventcodes(v=vs.110).aspx[^] If you want to catch session end - and maybe set a flag for later use - see for Globla.asax...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
Hmmm. It seems thatI misunderstood the example code that I took off the web. I will do some more research and re-attempt a solution. Question: What is the best way to perform a session timeout situation? Is it possible in the VS2010 IDE ? I've been publishing my App to a Sandbox IIS7 server and I've set the timeout to 1 minute, but this is cumbersome and difficult to debug. Thanks for your help.
-
Hmmm. It seems thatI misunderstood the example code that I took off the web. I will do some more research and re-attempt a solution. Question: What is the best way to perform a session timeout situation? Is it possible in the VS2010 IDE ? I've been publishing my App to a Sandbox IIS7 server and I've set the timeout to 1 minute, but this is cumbersome and difficult to debug. Thanks for your help.
You can add a button (in debug mode) that will call Session.Abandon[^] for you...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
You can add a button (in debug mode) that will call Session.Abandon[^] for you...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
session.Abandon() is exactly what I needed. Test is perfect. I will start a new thread for my next issue. "Response.Redirect" is not allowed in Callback. Thanks for all your help.
-
session.Abandon() is exactly what I needed. Test is perfect. I will start a new thread for my next issue. "Response.Redirect" is not allowed in Callback. Thanks for all your help.
Glad to help...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)