如何知道一个用户离开网站或立即关闭浏览器窗口,在服务器端? [英] How to know a user has left the website or close the Browser window immediately in server side?

查看:292
本文介绍了如何知道一个用户离开网站或立即关闭浏览器窗口,在服务器端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET中,将Session_End中当届超时然后我可以猜测用户已经离开或在这种方法关闭浏览器窗口被解雇。

In ASP.NET, Session_End will be fired when the Session is time out then I can guess the user has left or close the Browser window in this method.

但有一些延迟,直到超时,有没有更好的解决办法?

But there is some delay till time out, is there any better solution?

推荐答案

由于有很多事情可以中断用户的访问就像失去联系,或浏览器崩溃;你应该依靠客户端告诉服务器嘿,我还在这里。并假定他们离开时,他们停止这样做,这样,而不是让客户告诉他们离开了服务器。

Since there are many things that can interrupt a user's visit like a lost connection, or a browser crash; you should rely on the the client to tell the server "Hey I am still here." and assume they left when they stop doing so that rather than have the client tell the server they left.

要做到这一点,你可以使用什么被称为心跳:结果
http://ajaxpatterns.org/Heartbeat

To accomplish this, you can use what's known as the "Heartbeat":
http://ajaxpatterns.org/Heartbeat

您可以调整心跳间隔这样效果会更直接。这样做,你也可以调整你认为是用户活动。依托功能燃煤 onunload的将导致谁离开自己的电脑,但没有关闭浏览器窗口,用户似乎是积极的。

You can tweak the heartbeat interval so the effect can be more immediate. Doing that you can also tweak what you consider "user activity." Relying on functions fired onunload will cause users who left their computer but didn't close their browser window appear to be "active."

这篇关于如何知道一个用户离开网站或立即关闭浏览器窗口,在服务器端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆