TAGS :Viewed: 9 - Published at: a few seconds ago

[ Preventing the closing of IE browser from taskbar from ASP.NET application ]

I have to asp.net application, I need to prevent the user from closing the application from the right click on IE menu in the taskbar and closing it when the user is signed on to the application. Is there a way to disable the close menu or get the close event in the application and use the event to do the logoff and then close the browser?


Answer 1

Sorry, I don't think you're going to be able to get that much control of the browser from any web app, regardless of whether it's ASP.NET or something else.

Answer 2

try this

< html> 
< head>
< title>< /title>
< /head>

< body onbeforeunload="alert('Closing');">
< /body> 
< /html>

but keep in mind that there are some other ways to close an explorer that u cant catch..

After i wrote this, i give it a shot and find a really annoying thing, the onbeforeunload and onunload events are triggered not only when the window closes, but also during normal page navigation.

a work around may be this: The most solid way is to call some function during the onbeforeunload event, and to have that function look for some "flag" variable. All your links would have to set this variable so that the function knows a link was clicked, whereas the browser close wouldn't set that variable and ta-da - you can now differentiate a close event from a navigate one. The downside to this method is that you have to add code to every link click, and that menubar navigation (i.e., back button, etc.) wouldn't set the flag properly. However, it's the best I've seen so far.

Answer 3

If you use persistent cookies for authentication the correct behavior is to keep the user logged in even if he closes the browser. If this behavior is not desired, then use session cookies. These cookies expires when the user closes the browser so he would be logged out.