<p>In ASP.NET, I'm looking for a way to audit a user leaving my application. To be specific, I'd like to insert a 'logout' record in an audit table in SQL Server when the user's session is abandoned/destroyed for any reason (not necessarily because of a call to session.abandon)</p>

<p>I have a 'SessionHelper' class that manages the session setters/getters.</p>

<p>I've tried posting back in Session_End in Global.asax, but it never fired this event even after the timeout expired.</p>

<p>I've tried overriding 'finalize' in the SessionHelper class and doing it there when the class is destroyed, but it did not fire that event either.</p>

<p>I'd try implementing IDisposable in the SessionHelper, but I don't know where to call it so that it always gets called.</p>

<p>What is the proper way to audit a user leaving your ASP.NET application?</p>

<p>Thank you!</p>

Note sure about the "proper way" but here's how I've done it in the past.
Have a "is active" date-Time stamp associated with the user record in the database. Everytime the user accesses a page, that is updated to the current time. If someone hasn't accessed the page in say 15 minutes, then that user is recorded as a "logout" event, and the timestamp is set to NULL.