Save settings on exit

  • Thread starter Thread starter Jaco Bregman
  • Start date Start date
J

Jaco Bregman

Hi all,

I have been trying to save some user settings when my web application
closes, but with little success. What I want to do is start a counter on
startup, and write the total count to a database when the user logs off, or
when the user closes the web browser. My problem is that I can't seem to
catch the 'close web browser' event, to write the counter. I've tried to use
the Session_End handler in global.asax, but that doesn't seem to work.

Any ideas?

Thanks,

Jaco
 
Howdy,

There's no server-side event which fires when the user closes the web
browser. The only way to do this, is to catch when the browser is closed
using client side code, and execute a server side page accordingly.

Hope this helps,

Mun
 
Now, Id' surely like to know how the browser is supposed to send a request
when it is closing. The only reliable way to snag the end of the browser
session is with the Session_OnEnd event.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
The way I've approached this in the past, is by using the onunload event,
and a global frameset. The global frameset can consist of one frame, which
contains the website. The frameset has an onUnload event handler attached,
to execute a server-side page when the user navigates away from the site (or
closes the browser). Navigating within the site will happen within the
frame, which won't fire the onUnload event.

E.g.

In the head section, we could have the following script:

<script language="javascript">
function window_onunload()
{
window.open("http://www.domain.com/dosomething.aspx");
}
</script>


Our frameset could consist of the following:

<frameset rows="100%" onUnload="window_onunload()">
<frame name="MainFrame" src="default.aspx" marginwidth="0"
marginheight="0" scrolling="auto" frameborder="0">
</frameset>

It's not quite the same as the browser firing an event when it's closing.
However, the above method can be applied to achieve relatively good results.
But, as a precaution, I agree that it's always best to use the Session_OnEnd
event, as this is the only reliable way to catch the end of a session and
the browser being closed down.

Mun
 
Back
Top