Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display first asp page after the form has been idled for 30min 1

Status
Not open for further replies.

920506

Programmer
Jun 13, 2003
201
US
Hi all,
I saw many web sites display the first asp page again
after you leave the form idling for a long time.
(in the case of you are in the middle of the entering data on forms)Can anybody shed a light on me?
Any clue will be fine.
Thank you.

Betty
 
There is probably a session variable that times out after some period of time.

Perhaps these sites you've seen have an include file on the top of all password protected pages. Perhaps the include file has some code like this:[tt]
If Len(Session("UserName")) = 0 Then
'user is not logged in or allowed session to expire
Response.Redirect "login.asp"
End If [/tt]

... the idea being that if the session expires or is abandoned then the session variable will be empty.
 
Sheco,
That sounds a way to approach it. I will try it. From my past experience. If you set your session will expired after 20min. Sometimes you still can access some session variable, some session variable is not accessible any more.
Session and cookie always confuse me.
Thank you.
Betty
 
920506,

Sheco's solution will work nicely in the event that the user navigates away from the page. However, like you said in your first post - if a user is filling out a form and gets up to walk away from their desk then it will sit on that form until someone intervenes.

If you combine Sheco's code with the html meta refresh tag then you can automate this process. By default session variables expire after 20 minutes. So, you can set the meta refresh tag to reload the page after 20.5 minutes or so. When this happens the page refreshes, hits Sheco's code and sees that the session variable no longer exists and redirects back to the login page.

Here's some info on the meta refresh tag:


-kaht

[small]How spicy would you like your chang sauce? Oh man... I have no idea what's goin' on right now...[/small]
[banghead]
 
And of course, you could always just make the meta tag navigate to the login page itself, and you wouldn't have to worry about checking the session variables.

-kaht

[small]How spicy would you like your chang sauce? Oh man... I have no idea what's goin' on right now...[/small]
[banghead]
 
Kaht,
thank you for your idea.The method you talked about is reload the page again every 20.5min without thinking if the page is idled or not. right?
I am just thinking if the page is idled for that long then take action to redirect to a specific page based on the program.
betty

 
In that case you would want to use javascript to redirect the page rather than a meta refresh tag. Then you would need to determine what you consider to be 'idle'. You could easily hook up a counter that counts the seconds since the user last moved and reset it with every mouse move event that is fired. If it reaches a certain number of seconds (filled in from your ASP code to keep it in line with your session timeout) then you could redirect.
Code:
<html>
<head>
<script language="Javascript">
var timeoutCounter = 0;   //counter to compare against
var timeoutInterval = 5;  //interval/num seconds between counts so this would be every 5 seconds, 30 would be every 30 seconds, etc
var maxTime = 60 * 20.5;  //the 20.5 could easily be input from ASP as <%=yourvar%>

//function to increment timeout
function incrementTimeout(){
   timeoutCounter += timeoutInterval;
   if(timeoutCounter >= maxTime)
      document.href="login.asp"
}

//function to reset timeout
function resetTimeout(){
   timeoutCounter=0;
}

//set up an interval for the increment function to be called
setInterval("IncrementTimeout();",1000 * timeoutInterval);

//setup some events that will reset the counter to 0
document.onmousemove=resetTimeout
document.onkeydown=resetTimeout
</script>

I wrote that on the fly so I may have misremembered something (I think document.href is valid) or mistyped something, but the basic concept should be sound. By filling in the maxTime dynamically, such as using Session timeout + .5, you can make it fit your site a little better. Additional events could be used if you want, but I think mouse movement ad keypresses should pretty much cover user interaction.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top