Kill Session Variables When User Closes Browser Window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spoonybard
    New Member
    • Nov 2007
    • 19

    Kill Session Variables When User Closes Browser Window

    Hi Everyone,

    I have a .Net 2.0 C# web application that has important information stored in Sessions that needs to be deleted when the user closes the browser. I know of three ways a user can close their browser:
    1. Presses "X" button in top right of browser
    2. Presses Alt-F4
    3. From browser menu selects File -> Close

    With javascript I am able to detect that the user presses the X button. Since Javascript is client side and ASP.Net is server side, I can't find a way to kill the sessions through javascript.

    Are there any .Net methods for detecting the closing of the browser window so that I can do a call to "Session.Abando n()"? The method must be cross-browser compatible for at least IE6, IE7 and Firefox.

    Thanks.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    If the browser is closed, the session ID it had is lost, so they cannot get it back from your server.
    All Session data itself is stored on the server, and normal behavior is to automatically flush it out after 20mins of inactivity by the user.

    So I am not sure what the point of knowing when they close their browser is, as they cannot re-open their browser and get the same session back.

    Comment

    • spoonybard
      New Member
      • Nov 2007
      • 19

      #3
      We have a website that the user goes to. On the page are several links to another one of our websites. Those links pop up the other website in a new window. If the person closes the new window and then clicks a link on the original page, when the new window opens, the original session data is still being held onto.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Because the browser was never closed.
        Closing "popup" child windows does not count as leaving the website.
        If you are using javascript to open the windows, create an object for the window and then keep checking for when it goes to null(or if a property changes, would have to check the javascript DOM on window objects) which would be when the child window gets closed.
        That might be more what you are after.

        Comment

        Working...