"Non-persistent" session variables

A

Arnost Sobota

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

Bob Barrows [MVP]

Arnost said:
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.
 
A

Arnost Sobota

Bob Barrows [MVP] a écrit :
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.
 
P

Patrice

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

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top