jknj72
asked on
Session timeout issue
I have a question already posted about trying to Redirect my app to my Login page after Session_End fires. I have been trying to get around this all day and I was doing some research and found a piece of javascript code that would display a message when the Session timeout interval was complete. I thought I could put this in my Master page Page_Load event and reset the interval everytime its hit, thus restarting the time it would take for the message to display. Im incorrect on this.
What seems to be happening is, when this code gets hit and lets say the interval is 60 seconds. I do another action, lets say 15 seconds later, to cause another Postback and the code to get hit again. I thought that this would restart the interval to another 60 seconds but it wont. The first call is still in play, meaning after the initial 60 seconds even though I caused another postback, the message would appear. I want the script to somehow reset itself every time it gets hit.
Bottom line is I want to notify the user with an alert that the Session has ended and they will be redirected back to the login screen. This script would be perfect if I can get it to restart or extend the interval every time it gets hit, kinda like with Session. Is it somehow possible for me to cancel the first call and have this one be the only one to run at that point?
I hope this makes sense? I know I write like a caveman.
Here is the code I initially had in a class and would inherit the class on every page I wanted to have the session timeout to refresh.
What seems to be happening is, when this code gets hit and lets say the interval is 60 seconds. I do another action, lets say 15 seconds later, to cause another Postback and the code to get hit again. I thought that this would restart the interval to another 60 seconds but it wont. The first call is still in play, meaning after the initial 60 seconds even though I caused another postback, the message would appear. I want the script to somehow reset itself every time it gets hit.
Bottom line is I want to notify the user with an alert that the Session has ended and they will be redirected back to the login screen. This script would be perfect if I can get it to restart or extend the interval every time it gets hit, kinda like with Session. Is it somehow possible for me to cancel the first call and have this one be the only one to run at that point?
I hope this makes sense? I know I write like a caveman.
Here is the code I initially had in a class and would inherit the class on every page I wanted to have the session timeout to refresh.
Dim int_MilliSecondsTimeOut As Integer = (Me.Session.Timeout * 60000)
Dim str_Script As String = vbCr & vbLf & vbCr & vbLf & " <script type='text/javascript'> " & vbCr & vbLf & vbCr & vbLf & " intervalset = window.setInterval('Redirect()'," + int_MilliSecondsTimeOut.ToString() + ");" & vbCr & vbLf & vbCr & vbLf & " function Redirect()" & vbCr & vbLf & vbCr & vbLf & " {" & vbCr & vbLf & vbCr & vbLf & " alert('Your Session has expired. You will be redirected to the login page.\n\n');" & vbCr & vbLf & vbCr & vbLf & " window.location.href='/userlogin.aspx'; " & vbCr & vbLf & vbCr & vbLf & " }" & vbCr & vbLf & vbCr & vbLf & "</script>"
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "Redirect", str_Script, False)
ASKER
if I have to I can prob create one.... what were you thinking?
ASKER
I cant be the only person who has run into this scenario.... Im not stuck on the way im doing it by any means so if there is a better, easier way please feel free...
maybe I dont get what is wrong here...
what js do you have on page?
from the code, I see that
you open a page, and after 60 sec, there is an alert and go to login page...
and on every post/refresh/new page load, this will start again from 0...
whats wrong here?
what js do you have on page?
from the code, I see that
you open a page, and after 60 sec, there is an alert and go to login page...
and on every post/refresh/new page load, this will start again from 0...
whats wrong here?
ASKER
Ok I load the page and the script gets hit. I load the page again and the script gets hit again but the message will appear from the first time the script was hit. It doesn't seem to get refreshed or start over the second time the code is hit... If it would refresh I'd be good to go but it doesn't
how that js is rendered on the page
need to see html code rendered on browser...
need to see html code rendered on browser...
ASKER
Ok I'll have to do it in the morning. Thanks for the help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
trying a new way to do this
unless you do a
- ajax call
- use update panel...
do you have such scenarios?