Reputation: 1
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
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:
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
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
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