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.
On the internet you mostly find the approach to intercept the window.unload
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 window.unload
, 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.
There is the second approach of implementing a Heartbeat 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.
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.