Looking for a way to prompt a user to stay logged in before an automatic timeout, and an auto-save just before being logged out?
I am using forms authentication, and have a timeout of 30 minutes.
What I am looking for is some way of prompting the user with a few minutes to go that they are about to be timed out, and if they want to keep their session alive.
We have some fairly large forms with the users filling in a lot of data. They'll开发者_JAVA技巧 have been checking others systems for info, cross checking with colleagues on the phone, etc.
I also want to add an auto-save just before they are timed out as well.
Are these easy things to achieve with JQuery for example?
The solution we found on our project was to create a javascript (not necessarily jQuery) which prompts the user before they're logged out, and sends a bogus httpRequest in order to keep the session alive.
our script was something like (untested):
var promptUserTimeoutId = 0;
promptUserTimeoutId = setTimeout(promptUser, 30 * 60 * 1000); //call just once, in 30 minutes
function promptUser() {
if (alert('stay logged in?')) {
sendHttpRequest(); //just signal a keep-alive to the server...
//re-set the 30 minutes count
clearTimeout(promptUserTimeoutId);
promptUserTimeoutId = setTimeout(promptUser, 30 * 60 * 1000);
}
}
function keepSessionAlive(timeLeft)
{
var timer = setTimeout(function(){
//Prompt the user to keep the session alive;
//make a dummy request via ajax to refresh the session on the server.
//reset the timeLeft to your timeout
//call keepSessionAlive(timeLeft)
},timeLeft);
}
Then on document load you can call your method.
body.onload=keepSesionAlive(<yourTimeOut-3 to 4 minutes>);
I dont know of a jquery way of doing this though.
精彩评论