简体   繁体   中英

Fired an event in asp.net when Session expired or browser close

i want to fire an event in asp.net when my user session has been expired or i close browser. actually i want to update some thing in database according to login user when he/she leave the site.

请参阅此处的会话状态事件文档: http : //msdn.microsoft.com/zh-cn/library/ms178583.aspx

Unfortunately this question is very close to "I want to save my data after computer is turned off"... Very hard and not predictable.

  • Session termination events are not fired for out of process sessions
  • Users simply close browsers, logout or turn of machines without any cahnce to notify your site
  • or even worse - instead of watching ads and actively looking at your site they just leave browser open and go drink, sleep...
  • Or browsers can crash

Now sometimes you can try to handle unload events for browser... you may have enough time to send response sometime.

Probably most reliable solution is to have heartbeat requests from browser and mark users as active this way (in custom database/storage). Periodically check and mark all users that did not send heartbeat requests for some time...

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