Save settings on exit

Discussion in 'ASP .Net' started by Jaco Bregman, Nov 17, 2003.

  1. Jaco Bregman

    Jaco Bregman Guest

    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
     
    Jaco Bregman, Nov 17, 2003
    #1
    1. Advertising

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



    "Jaco Bregman" <> wrote in message
    news:...
    > 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
    >
    >
     
    Munsifali Rashid, Nov 17, 2003
    #2
    1. Advertising

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

    "Munsifali Rashid" <mun@**RemoveToReply**vefuk.com> wrote in message
    news:...
    > 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
    >
    >
    >
    > "Jaco Bregman" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
     
    Kevin Spencer, Nov 17, 2003
    #3
  4. 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




    "Kevin Spencer" <> wrote in message
    news:%...
    > 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.
     
    Munsifali Rashid, Nov 18, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,904
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. Joe Smith
    Replies:
    4
    Views:
    65,865
    sandeep1976
    Nov 8, 2006
  3. Replies:
    2
    Views:
    459
    Jeff Epler
    May 31, 2005
  4. Mel
    Replies:
    10
    Views:
    3,129
    Sailaja Appi
    Feb 13, 2009
  5. donet programmer
    Replies:
    3
    Views:
    1,551
    Gregory A. Beamer
    Nov 20, 2009
Loading...

Share This Page