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

前端 未结 2 1132
逝去的感伤
逝去的感伤 2021-01-27 08:09

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

相关标签:
2条回答
  • 2021-01-27 08:30

    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...

    0 讨论(0)
  • 2021-01-27 08:47

    See the session state events documentation here: http://msdn.microsoft.com/en-us/library/ms178583.aspx

    0 讨论(0)
提交回复
热议问题