简体   繁体   English

一段不活动后的会话超时

[英]Session timeout after period of inactivity

I have an application that requires a login and I also have an AJAX timer. 我有一个需要登录的应用程序,我也有一个AJAX计时器。 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. 但是,如果用户没有点击某个按钮5分钟,我希望会话结束。 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页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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