简体   繁体   中英

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

I want to Kill session on browser close or tab close in 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). And implement endpoint on your server that works with session state and refreshes it, so client session can have 5 more minutes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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