更新数据库表和终止会话的浏览器关闭时 [英] Update the database table and kill the session when the browser closes

查看:111
本文介绍了更新数据库表和终止会话的浏览器关闭时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要当用户关闭浏览器/标签更新表(IE,FF,Chrome浏览器,Opera和Safari)。

I need to update the table when the user closes the browser/tab (IE,FF,Chrome,Opera and Safari).

我放在卸载事件母版,但卸载事件被解雇仅在第一次。每隔卸载事件不会开火。

I placed the unload event in MasterPage but the unloading event is firing only the first time. Every other unload event is not firing.

推荐答案

beforeunload 活动将做你想做的,只要用户仍然登录时,他们关闭浏览器。

The beforeunload event will do what you want, provided the user is still logged in when they close the browser.

但是你永远无法100%肯定让事件。

But you can never be 100% certain of getting the event.

用户可能会失去其网络连接,或者死机的电脑等,这将有同样的效果,但它,你永远不会得到通知。

The user may lose their network connection, or crash their computer, etc, which would have the same effect, but you'd never get notified of it.

和,因为它是一个客户端的动作,它可以通过一个恶意脚本或由用户拦截攻击。

And because it's a client-side action, it could be intercepted by a malicious script or hacked by the user.

底线是:做不会靠这个功能。你需要让你的会议自然死亡的浏览器被关闭,即使是你从来没有收到通知。标准的方式做,这是一个闲置一段时间后超时。

The bottom line is: Do NOT rely on this functionality. You need to allow your sessions to die naturally even if are you never notified of the browser being closed. The standard way to do this is with a timeout after a period of inactivity.

如果你要允许反正就是有什么需要,积极杀死浏览器关闭会话?你可能也只是让他们都用超时自然死亡。

And if you're going to allow that anyway, is there any need to actively kill sessions on browser close? You may as well just let them all die naturally with a timeout.

这篇关于更新数据库表和终止会话的浏览器关闭时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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