如何在关闭的浏览器或选项卡事件中删除所有会话 [英] how to remove all Session in close browser or tab event

查看:134
本文介绍了如何在关闭的浏览器或选项卡事件中删除所有会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想在关闭页面活动中删除所有会话但我不知道该怎么做?

我在点击事件中为链接按钮这样做

请帮帮我



我的代码:

Hi I want to remove all Session in close page event but I don't know how to do that?
I do that in click event for link button
please help me

my code:

Session.RemoveAll();
       Response.Redirect("~/Default.aspx");

推荐答案

浏览器关闭是一个浏览器功能,纯粹是一个客户端事件,与服务器端代码无关,并且不会触发指示浏览器已关闭的事件。您必须使用onbeforeunload事件触发弹出窗口以在浏览器即将关闭时通知用户,然后您可以进行AJAX调用以调用服务器端方法(但您无法保证你的服务器端代码将执行)。



另请注意,当用户点击超链接或尝试关闭浏览器窗口时,此事件也会触发。



您可能希望尝试减少身份验证cookie的持续时间(如果您使用的是表单身份验证)。如果用户在超时期限内未在应用程序中处于活动状态,这将基本上将用户注销,如果设置为较小的值,则可能会在用户返回应用程序之前到期。



您可能还会考虑使用像SignalR这样的实时技术,使用他们的连接ID在整个应用程序中跟踪用户,然后如果您看到他们在一定时间后处于空闲状态,请处理相应地调用Session.Abandon()方法。
The browser close is a browser functionality, and is purely a client-side event that has nothing to do with your server-side code and will trigger no events to indicate that the browser was closed.You have to use onbeforeunload event to trigger a popup to notify users when the browser is about to close, You can then make an AJAX call to invoke a server-side method ( but you cannot guarantee that your server-side code will execute).

Also keep in mind that this event will also trigger when the user clicks on the hyperlink or attempts to close the browser window.

You might want to try decreasing the duration for your authentication cookie (if you are using Forms Authentication). This will essentially log your user out if they have not been active within the application past the duration of your timeout, which if set to a small value will likely expire prior to the user returning to the application.

You might also consider using a real-time technology like SignalR to essentially "track" a user throughout your application using their Connection ID and then if you see that they are idle after a certain duration, handle that accordingly and call the Session.Abandon() method.


这篇关于如何在关闭的浏览器或选项卡事件中删除所有会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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