"Non-persistent" session variables

Discussion in 'ASP General' started by Arnost Sobota, Oct 23, 2006.

  1. Dear ASP community,

    I have a question regarding ASP session variables.

    My assumption was that a session variable has the same lifetime as the
    session itself: as a consequence, given that closing the browser doesn't
    terminate the session, the session variable is kept alive until the
    session expires.

    But, surprisingly, I've found this to be true for the session variables
    whose value is set in the global.asa file, but if the value is set in an
    ..asp script, it appears to be erased from the session object as soon as
    the browser is closed although the session is still alive. Strange. Is
    this a bug?

    What I'd need to know is: how I can make session variables whose value
    is set in an .asp script persistent as long as the session is alive.

    Thank you for your help,

    A. S.
    Arnost Sobota, Oct 23, 2006
    #1
    1. Advertising

  2. Arnost Sobota wrote:
    > Dear ASP community,
    >
    > I have a question regarding ASP session variables.
    >
    > My assumption was that a session variable has the same lifetime as the
    > session itself: as a consequence, given that closing the browser
    > doesn't terminate the session, the session variable is kept alive
    > until the session expires.
    >
    > But, surprisingly, I've found this to be true for the session
    > variables whose value is set in the global.asa file, but if the value
    > is set in an .asp script, it appears to be erased from the session
    > object as soon as the browser is closed although the session is still
    > alive. Strange. Is this a bug?


    No. It's impossible. The server has no way of knowing the browser has
    been closed.

    Of course, once you close the browser, you have no way to access the
    values set in the previous session (opening a new browser window
    initiates a new session), so how are you determining that the values are
    being erased when the browser window is closed?

    Provide a repro script we can run to exhibit the behavior you are
    seeing.



    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Oct 23, 2006
    #2
    1. Advertising

  3. Bob Barrows [MVP] a écrit :
    > Arnost Sobota wrote:
    >> Dear ASP community,
    >>
    >> I have a question regarding ASP session variables.
    >>
    >> My assumption was that a session variable has the same lifetime as the
    >> session itself: as a consequence, given that closing the browser
    >> doesn't terminate the session, the session variable is kept alive
    >> until the session expires.
    >>
    >> But, surprisingly, I've found this to be true for the session
    >> variables whose value is set in the global.asa file, but if the value
    >> is set in an .asp script, it appears to be erased from the session
    >> object as soon as the browser is closed although the session is still
    >> alive. Strange. Is this a bug?

    >
    > No. It's impossible. The server has no way of knowing the browser has
    > been closed.
    >
    > Of course, once you close the browser, you have no way to access the
    > values set in the previous session (opening a new browser window
    > initiates a new session), so how are you determining that the values are
    > being erased when the browser window is closed?
    >
    > Provide a repro script we can run to exhibit the behavior you are
    > seeing.
    >
    >
    >

    Bob,
    Silly me! Of course you're one-hundred-percent right! I simply forgot
    that opening a new browser window initiates a new session and that there
    is no way to access the session variables from another session.

    A. S.
    Arnost Sobota, Oct 23, 2006
    #3
  4. Arnost Sobota

    Patrice Guest

    Are you sure they are kept ? IMO the code you have in global.asa (usally in
    the session start event) just creates them again so when you browse the site
    they always appears there (not because they are kept but because you have
    created them again). Store also the SessionID or the current datetime and
    you should see this is not the same value.

    Else give some more details about how they are created (in global.asa, which
    event, how (in case it would be a confusion between static application
    scoped variable declared with the object tag and session variables).

    When you close/reopens the browser, the session is kept on the server but he
    server will create a new session if you reconnect (the temporary cookie used
    for sessions is stored in memory and is deleted when the browser is closed).

    --
    Patrice

    "Arnost Sobota" <> a écrit dans le message de news:
    453cc7c2$0$25913$...
    > Dear ASP community,
    >
    > I have a question regarding ASP session variables.
    >
    > My assumption was that a session variable has the same lifetime as the
    > session itself: as a consequence, given that closing the browser doesn't
    > terminate the session, the session variable is kept alive until the
    > session expires.
    >
    > But, surprisingly, I've found this to be true for the session variables
    > whose value is set in the global.asa file, but if the value is set in an
    > .asp script, it appears to be erased from the session object as soon as
    > the browser is closed although the session is still alive. Strange. Is
    > this a bug?
    >
    > What I'd need to know is: how I can make session variables whose value is
    > set in an .asp script persistent as long as the session is alive.
    >
    > Thank you for your help,
    >
    > A. S.
    Patrice, Oct 23, 2006
    #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. Ryan

    Non persistent page cache

    Ryan, Jan 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    414
    Paul Glavich
    Jan 21, 2004
  2. Marco Rispoli

    Non-persistent cookie

    Marco Rispoli, May 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    590
    clintonG
    May 8, 2004
  3. hochun

    non-persistent cookies

    hochun, Jun 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    374
    John Saunders
    Jun 2, 2004
  4. hochun

    Re: non-persistent cookies

    hochun, Jun 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    390
    John Saunders
    Jun 3, 2004
  5. Vinc
    Replies:
    0
    Views:
    430
Loading...

Share This Page