ASP.Net Form Authentication - Go to the login page with a timeout

Is it possible to redirect to the login page when a timeout occurs, without waiting for the user to click on something first? Right now, when a timeout occurs, the page user is still displayed, but as soon as the user clicks on something, he goes to the login page. Thanks.

+4
source share
2 answers

You need to check on the client side if the session has expired. The easiest way is to simply start the countdown (before the timeout), using javascript when the page loads. After this period, send the user to the login page. Or maybe itโ€™s better: just tell the user that the session has expired, because maybe he wouldnโ€™t be too happy if you just sent it somewhere. Although my online banking software does just that, but for security reasons, of course.

Here is a very simple example: http://jsfiddle.net/39Sj6/1/

function sessionHasExpired(){ if(confirm("Your session has expired. Do you want to go to the login page")){ window.location = "http://google.com/?q=login"; } } var sessionTimeInMilliseconds = 1000*60*5; // here: 5 minutes setTimeout(sessionHasExpired, sessionTimeInMilliseconds ); 

(In jsfiddle, you will not be redirected to google, as this is forbidden by jsfiddle, but in principle it will work)

+5
source

Yes, you can either query the session state using a Javascript timer, or an ajax call to check the server session status, then redirect to the login page or set a timer with a specified time (20 minutes or session timeout), and then redirect to login page.

0
source

Source: https://habr.com/ru/post/1399420/


All Articles