关闭浏览器或选项卡时关闭/终止会话 [英] Close/kill the session when the browser or tab is closed

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

问题描述

有人能告诉我如何在用户关闭浏览器时关闭/终止会话吗?我正在为我的 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屋!

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