简体   繁体   English

为Web应用程序实现空闲超时的最佳方法是什么(自动注销)

[英]What is the best way to implement idle time out for web application (auto log off)

I want to implement an idle time-out for the web application that we are building. 我想为我们正在构建的Web应用程序实现空闲超时。 I had earlier achieved this using AsynchronousSessionAuditor from codeplex, which essentially looks for the formsauthentication and session cookie timeout by constant polling. 我之前使用Codeplex中的AsynchronousSessionAuditor实现了这一点,它基本上通过常量轮询查找formsauthentication和会话cookie超时。

But it has a draw back of not respecting the client side events, it will look for only last postback to decide when to log off. 但它有一个不尊重客户端事件的缺点,它只会寻找最后一个回发来决定何时注销。

The jquery plug jquery-idle-timeout-plugin from erichynds solves this issue of client side events but suffers from another drawback that is not able to recognise user is active on some other tab. 来自erichynds的jquery插件jquery-idle-timeout-plugin解决了这个客户端事件的问题,但是遇到了另一个无法识别用户在其他选项卡上处于活动状态的缺点。

Is there anyone already fixed the TABBED browsing issue with jquery-idle-timeout-plugin already? 有没有人已经用jquery-idle-timeout-plugin修复了TABBED浏览问题? Or is there any better approach of application time out for web applications (by the way this web app is build using asp.net f/w) 或者是否有更好的Web应用程序应用程序超时方法(通过使用asp.net f / w构建此Web应用程序)

If I understand your question right, it is not possible, since there are no events triggered in javascript for activity outside of the current window/tab. 如果我理解你的问题是正确的,那是不可能的,因为在javascript中没有触发当前窗口/选项卡之外的活动的事件。

Unless you have a addon to go along with your website for each browser, which could monitor all activity in the browser, but that is not really a practical approach. 除非你有一个插件与你的网站一起用于每个浏览器,它可以监控浏览器中的所有活动,但这不是一个真正的实用方法。

Well, you'd have to code it by hand, which is not really hard. 好吧,你必须手工编写代码,这并不是很难。 You can use the onfocus and onblur functions to do something like this: 您可以使用onfocus和onblur函数执行以下操作:

$(function() {
    window.isActive = true;
    $(window).focus(function() { this.isActive = true; });
    $(window).blur(function() { this.isActive = false; });
    showIsActive();
});

function showIsActive()
{
    console.log(window.isActive)
    window.setTimeout("showIsActive()", 2000);
}

function doWork()
{
    if (!window.isActive) { /* Check for idle time */}
}

If you make a little search you can find that varaieties of this question have already been asked and answered, you can probably find a solution you can implement with one of the plugins you mentioned. 如果你进行一些搜索,你会发现这个问题的变种已经被问及并得到解答,你可以找到一个解决方案,你可以使用你提到的其中一个插件来实现。

Try: Run setTimeout only when tab is active or How to tell if browser/tab is active 尝试: 仅在选项卡处于活动状态时运行setTimeout如何判断浏览器/选项卡是否处于活动状态

EDIT--> ADDED: 编辑 - >增加:

Or I'd try a different approach. 或者我尝试不同的方法。 You could create a cookie with some hash and save that hash in your DB with a timestamp that updates whenever the window is active (you could check every 5 seconds or something, it's not an intensive request) 您可以使用一些哈希创建一个cookie,并在数据库中保存该哈希值,并在窗口处于活动状态时更新时间戳(您可以每5秒检查一次,这不是密集请求)
Then, do another check before(but in the same request) to see how much time has passed since the last timestamp and log them out if necessary. 然后,在之前进行另一次检查(但在同一请求中)以查看自上一个时间戳以来已经过了多少时间并在必要时将其记录下来。
it won't log them out isntantly when time has passed, but it will when they try to access the site either by opening it again or by focusing on the tab/window. 它不会在时间过去时将它们记录下来,但是当它们试图通过再次打开它或通过关注选项卡/窗口来访问该站点时它们将会被记录下来。

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

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