简体   繁体   中英

Session timeout after period of inactivity

I have an application that requires a login and I also have an AJAX timer. I have read several posts on how to create a session timeout after a certain period of time. However, I want the session to end if the user hasn't clicked a certain button for say, 5 minutes. Is there a way to reset the timer after every click?

Try this:

function logout() { 
    location.href = '/your/logout/page.aspx';
}

var timeout = setTimeout(300000, logout);
function resetTimeout() {
    clearTimeout(timeout);
    timeout = setTimeout(300000, logout);
}

document.onclick = resetTimeout;

您可以在页面加载(使用setTimeout)上设置一个javascript计时器,并且每个回发后都会重置(并且可选地通过不回发的按钮单击),并且当该计时器倒计时到零时,它将重定向到一个logout.aspx(例如:window.location ='Logout.aspx'),用于处理清除会话,然后重定向回Login页面。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM