杀Asp.Net会话时,浏览器或标签被关闭 [英] Kill Asp.Net session when the browser or tab is closed

查看:120
本文介绍了杀Asp.Net会话时,浏览器或标签被关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用窗体身份验证与Asp.Net 4.目前当用户在注销链接点击,我清除了会议,并调用 FormsAuthentication.SignOut()和这$ p $在再次回到现场没有记录pvents用户。

I am using forms authentication with Asp.Net 4. At the moment when the users click on logout link, I clear the session and call FormsAuthentication.SignOut() and this prevents the users from going back to the site without a logging in again.

现在我想在浏览器或标签被关闭,终止会话。我试图通过处理 onbeforeunload 事件这样做,但我最终点击任何内部链接后杀死了会议。

Now I want to kill the session when the browser or tab is closed. I tried doing this by handling onbeforeunload event, but I ended up killing the session after clicking any internal links.

任何想法我怎么可以这样?

Any ideas how I can do this?

推荐答案

的身份验证cookie的是会话只,这意味着通过浏览器在浏览器关闭删除。也许你不关闭所有浏览器标签的,但如果你将其关闭所有身份验证Cookie都将丢失。

The authentication cookies are session only, that means that delete by browser when the browser close. Maybe you do not close all browsers tabs, but if you close them all the authentication cookies are lost.

关于关闭选项卡,你不知道,如果用户有其他选项卡中打开。

About closing a tab, you do not know if the user have other tab opens.

一个可能的解决方案可能是一个电话,每10秒回服务器,以保持这种积极的身份验证或没有,设置身份验证20秒后结束了。因此,如果没有任何信号回来,用户也水涨船高。这可以使用JavaScript来完成。从另一方面,这不能让闲置了几分钟,用户注销,所以你可能需要用别的东西这个逻辑的组合。

A possible solution maybe is a call every 10 seconds back to the server to keep this authentication active or not, and set the authentication to end up after 20 seconds. So if not any signal come back, the user have gone. This can be done using javascript. From the other hand this can not let the user logout after some minutes of inactivity, so you may need a combination of this logic with something else.

这篇关于杀Asp.Net会话时,浏览器或标签被关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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