关闭浏览器或选项卡时关闭/终止会话 [英] Close/kill the session when the browser or tab is closed
问题描述
有人能告诉我如何在用户关闭浏览器时关闭/终止会话吗?我正在为我的 asp.net web 应用程序使用 stateserver 模式.onbeforeunload
方法不正确,因为它在用户刷新页面时触发.
Can somebody tell me how can I close/kill the session when the user closes the browser? I am using stateserver mode for my asp.net web app. The onbeforeunload
method is not proper as it fires when user refreshes the page.
推荐答案
你不能.HTTP 是一种无状态协议,因此您无法判断用户何时关闭了浏览器,或者他们只是坐在那里,打开浏览器窗口什么也不做.
You can't. HTTP is a stateless protocol, so you can't tell when a user has closed their browser or they are simply sitting there with an open browser window doing nothing.
这就是会话超时的原因 - 您可以尝试减少超时以更快地关闭不活动的会话,但这可能会导致合法用户的会话提前超时.
That's why sessions have a timeout - you can try and reduce the timeout in order to close inactive sessions faster, but this may cause legitimate users to have their session timeout early.
这篇关于关闭浏览器或选项卡时关闭/终止会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!