title: ASP.NET MVC: LogOut Heartbeat function
body: <p>Basically I am looking for a reliable log out mechanism when the user closes his tab. This includes calling some server code and thus all client side only mechanisms like deleting the cookie wont work for me.</p>
  
  <p>On the internet you mostly find the approach to intercept the <code>window.unload</code> function and then place some code in there. I know there is the possibility to filter out normal navigation requests from other events that might trigger <code>window.unload</code>, but I generally don't like this approach, as I have to make some sort of synchronous AJAX call in order to reliable execute some custom logout code on the server, which is definitely not the best way of achieving what I want.</p>
  
  <p>There is the second approach of implementing a <strong>Heartbeat</strong> function to periodically check if the client responds. I do think this is the best approach for me / my scenario, but I am actually struggling with the implementation with ASP.NET MVC.</p>
  
  <p>How would I approach this in ASP.NET MVC? I already thought of SignalR, but it's actually not directly possible to access session information within the SignalR context. </p>