user311078
user311078

Reputation: 1

To save to log out time

I want to save log out time when user close the Browser without clicking log out button using asp.net with C# and SQL server 2005.

kindly let me know the way as well as code..

Thanks in advance

Upvotes: 0

Views: 872

Answers (3)

Ocelot20
Ocelot20

Reputation: 10800

Like the other answers already state, you can't reliably know when a user has actually closed the browser. Your best bet would be to do something like this:

  1. User opens browser, session starts and records the fact that the user ID is associated with the session ID.
  2. User closes browser, nothing actually happens here.
  3. User opens new browser, server checks if current session ID matches the one linked to that user. If it doesn't, make them log in again.

This would only let you have one session per user ID though unless you came up with a more complicated system working on those basic ideas.

Upvotes: 0

Matthew Flaschen
Matthew Flaschen

Reputation: 284937

This is impossible to do reliably. You could hack something unreliable together with onunload and AJAX, but it's much simpler to just keep track of their last activity (i.e. the last time they send a request to the server).

Upvotes: 2

Joel Coehoorn
Joel Coehoorn

Reputation: 416081

There is no guarantee that your app will get any notice at all when the user's browser closes. The best you can do is log it when the session ends/expires. Even if you do figure out how to get a mostly-reliable notification, if you leave the session active they can always re-open the browser and with a little trickery get their old session back.

Upvotes: 2

Related Questions