How to catch an event when the user logs out of the application by clicking on any of the closing button(For Ex: Clicking on 'X' Button, or File-Close, or AltF4, or by navigating to some other pages by typing URL in address bar): Actually I am writing a function in java script for onbeforeunload like: <script language="javascript"> function HandleOnClose() { var newwindow = window.open("SignOut.aspx",target="MainForm"); newwindow.focus(); return false; } </script> This will fire when the page unload event occurs. But as my application is having many buttons, when the user clicks on any of the button(as the page gets refreshed) the above function is getting fired. So as to control this I am declaring one application variable in Application_BeginRequest event of the Global.asax.cs and I am assigning the value true to this. So when the user clicks on any of the button the control will comes to Application_BeginRequest event and then goes to the Page_Load of the MainForm and then comes back to the Application_EndRequest where I am updating the variable's value to false. From there the control is going to SignOut page. In the Page_Load of the SignOut page I am using this application variable to control the flow so as not to allow the button click event in the loop. This is working in my application correctly. But when I test this with several users, this is not working properly. Any Idea on how to go about this. Reply will be appreciated. Thanks in advance. Regards Srikanth.H