I want to re-direct the user to Home page when the session has expired during a post back. When the form timeout occurs then user is directed to login page.
Session timeout = 20, Form timeout = 2880
I tried the following code in the Global.asax, but does not work and causes Application_Error ("Response is not available in this context.").
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Response.Redirect("~/HomePage.aspx")
End Sub
The Session_End is not initiated by the browser (because any response from the browser should in theory extend the Session by another 20 minutes), therefore the concept of a Response object doesn't make sense.
The only option I can see would be to have some sort of client side script (javascript) that utilises the window.setTimeout function... something like (untested)...
<body onload="window.setTimeout(function(){document.location.href='/Home.aspx';},72000000);">
UPDATE
Having read the request again, the requirement is slightly ambiguous. If the requirement is for the webpage to automatically redirect after the 20 minutes (without user intervention), then my answer addresses that.
However, I think it's more likely that the requirement is to redirect to the homepage if the user sends another request to the server after the 20 minutes. In which case, MajoB's answer is a good one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With