By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

"Non-persistent" session variables

P: n/a
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.
Oct 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Oct 23 '06 #2

P: n/a
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.
Oct 23 '06 #3

P: n/a
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" <sa******@minefi.gouv.fra écrit dans le message de news:
45***********************@news.orange.fr...
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.

Oct 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.