I use c# asp.net 4 web.forms.
I have a page (lets called it X) I need execute a method on X in this situation only:
- When User visit another URL, directly input in the Browser or clicking another link on the Page.
- When User Log Out from my Web Application.
- When a User Close the Browser.
At the moment I’m trying Page_Unload Event but as for MSDN “Occurs when the server control is unloaded from memory” and I’m not able to make it works as expected.
Looking in the documentation I cannot find a suitable Event for my Page.
What are the possible alternative solutions? Thanks for your time on this.
This simply isn’t possible.
HTTP requires browsers to request resources from the server first – without this the server cannot do anything. Closing your browser will not request anything from the server.
Your only option is to use session cookies, which are wiped when the user ends the browsers session, as per MSDN:
So checking for these on each request will allow the server to know if the user has previously closed the browser.
There are nasty javascript solutions, but these are very much hacks.