Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want redirect to login page if the session expires. I got only a message. The page not redirected to login page.

The code is below:

Dim msgSession As String = "Warning: Within next 3 minutes, if you do not do anything, our system will redirect to the login page. Please save changed data.!"
        Dim int_MilliSecondsTimeReminder As Integer = (Me.Session.Timeout * 60000) - 3 * 60000
        'time to redirect, 5 milliseconds before session ends
        Dim int_MilliSecondsTimeOut As Integer = (Me.Session.Timeout * 60000) - 5
        Dim str_Script As String = vbCr & vbLf & "var myTimeReminder, myTimeOut; " & vbCr & vbLf & " clearTimeout(myTimeReminder); " & vbCr & vbLf & " clearTimeout(myTimeOut); " & "var sessionTimeReminder = " & int_MilliSecondsTimeReminder.ToString() & "; " & "var sessionTimeout = " & int_MilliSecondsTimeOut.ToString() & ";" & "function doReminder(){ alert('" & msgSession & "'); }" & "function doRedirect(){ window.location.href='Login.aspx'; }" & vbCr & vbLf & " myTimeReminder=setTimeout('doReminder()', sessionTimeReminder); " & vbCr & vbLf & " myTimeOut=setTimeout('doRedirect()', sessionTimeout); "
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "CheckSessionOut", str_Script, True)
Posted
Updated 24-Jun-11 2:19am
v2
Comments
R. Giskard Reventlov 24-Jun-11 8:20am    
Hard to see what is going on. Tidy up your code so it is readable. What message did you get? Shall we guess or can you tell us?
Sunasara Imdadhusen 24-Jun-11 8:36am    
Can you provide whole JavaScript after rendered page successfully? because we are not able to read it properly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900