It looks like you are doing a DB operation when you log out, and when people just move around without pressing the exit button, the code does not work.
In your global.asax take a look at session_end. Perhaps you can post your operation there.
protected void Session_End(Object sender, EventArgs e)
{
}
Note that if you use this, it actually fires when the IIS session ends, and not when the browser closes. By default, a session expires after 20 minutes of inactivity.
Once you implement this, you can start your Session.Abandon session exit page, which will call Session_End. It seems to me clean.
Here's an MSDN link with more information about session events: http://msdn.microsoft.com/en-us/library/ms178583.aspx
source
share