i need the browser ask me before closing it if i want to close or no .. i yes execute function named logoff in my app i'm using .net framework standard
Logout auto when client close the browser
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Nikunj SatasiyaRank #302 · 8.3K reputationPosted Jul 22, 2024, 5:56 AM EDT
Mohmed, Try this solution:
window.addEventListener('beforeunload', function (e) { // Cancel the event e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown // Chrome requires returnValue to be set e.returnValue = ''; }); window.onunload = function () { logoff(); }; function logoff() { // Async AJAX call to log off the user from the server var xhr = new XMLHttpRequest(); xhr.open("POST", "/PathToYourLogoutMethod", true); // Adjust the path to your logout method xhr.send(); }Nikunj SatasiyaRank #302 · 8.3K reputationPosted Jul 22, 2024, 7:50 AM EDT
Hi Mohame, it is based on your need, otherwise you can put this on any common place like shared page.
Mohamed abdelkader53 reputationPosted Jul 22, 2024, 7:16 AM EDT
which page i can put this code dear Nikunj