简体   繁体   English

如何在浏览器或选项卡关闭上实现Session.Abandon()?

[英]How to implement Session.Abandon() on Browser or tab close?

I want to Kill session on browser close or tab close in global.asax. 我想在global.asax中关闭浏览器或选项卡关闭时终止会话。 How to achieve it? 如何实现呢?

This doesn't seem to be possible in all cases. 似乎并非在所有情况下都可行。 "User closed browser" from server-side point of view look exactly like user browser crashed, Internet connection disappeared for couple days, user computer stop working and all kinds of events where there is no chance client code will send anything to your server signaling it is about to stop using your server. 从服务器端的角度来看,“用户关闭的浏览器”看起来完全像是用户浏览器崩溃,互联网连接消失了几天,用户计算机停止工作以及各种事件,在这种情况下,客户端代码不可能将任何内容发送到您的服务器,从而发出信号即将停止使用您的服务器。

Best workaround you can do is to have short-lived sessions on your server (5 minutes for example), then add javascript into all your pages to send periodical "keep alive" requests to your server (every minute or so). 最好的解决方法是在服务器上建立短暂的会话(例如5分钟),然后将javascript添加到所有页面中以向服务器发送定期的“保持活动”请求(每分钟左右)。 And implement endpoint on your server that works with session state and refreshes it, so client session can have 5 more minutes. 并在服务器上实现可处理会话状态并刷新它的端点,因此客户端会话可以再花5分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM