开发者

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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜