Sher Azam
Sher Azam

Reputation: 99

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.

Upvotes: 0

Views: 4213

Answers (2)

jeroenh
jeroenh

Reputation: 26792

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

Upvotes: 3

Alexei Levenkov
Alexei Levenkov

Reputation: 100555

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

Upvotes: 3

Related Questions