Search code examples
javascriptasp.netsessionserver-sideonbeforeunload

onBeforeUnload - how to call a server-side function without ajax


What I want to do: dispose of a session upon detecting an "OnBeforeUnload" event in the client. I know it doesn't fire 100% of times (90% accuracy works fine for me)

Here I saw how to do it with ajax, this system, however, breaks down with ajax: I can't use it at all.

I'm searching for ways of doing it


Solution

  • In short, you can't. You can't hold a user's browser hostage, which is what this would allow as an exploit if you could do what you want (e.g. redirecting on page exit). AJAX is your only option for a server-side call, and as you noted, that's unreliable as well.