Save settings on exit

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
 
M

Munsifali Rashid

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
 
K

Kevin Spencer

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.
 
M

Munsifali Rashid

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top