Problem with Session.Contents

C

Cecil Westerhof

I have the following code:

for each SesVar in Session.Contents
if( Session.Contents(SesVar) <> "" ) then

The problem is that most of the time this works okay, but sometimes the code
crashes on the compare. Anyone an idea what could be the problem?
 
R

Ray Costanzo [MVP]

Crashes? You mean that you are presented with an error message? What is
that message?

Ray at work
 
E

Evertjan.

Cecil Westerhof wrote on 23 nov 2004 in
microsoft.public.inetserver.asp.general:
for each SesVar in Session.Contents
if( Session.Contents(SesVar) <> "" ) then

[you can do without the () in vbs]

The variable value is in SesVar itself, so:

for each SesVar in Session.Contents
if SesVar <> "" then response.write SesVar & "<br>"
next

But then, Cecile,
an empty session variable does not exist anyway,
I think,
so the whole action can be simplyfied to:

for each SesVar in Session.Contents
response.write SesVar & "<br>"
next

dacht je niet?
 
A

Aaron [SQL Server MVP]

What does "crashes" mean? If it is type mismatch, then you might want to
make sure you exclude any arrays or other complex data types/objects from
your comparison. Please see http://www.aspfaq.com/2524
 
C

Cecil Westerhof

Evertjan. said:
Cecil Westerhof wrote on 23 nov 2004 in
microsoft.public.inetserver.asp.general:
for each SesVar in Session.Contents
if( Session.Contents(SesVar) <> "" ) then

[you can do without the () in vbs]

I know, but I find it more readable.

The variable value is in SesVar itself, so:

for each SesVar in Session.Contents
if SesVar <> "" then response.write SesVar & "<br>"
next

Not true I am afraid. SesVar contains the name, not the value. And I like to
have both. But the posting from Aaron gave me the solution I think.
 
C

Cecil Westerhof

Aaron said:
What does "crashes" mean? If it is type mismatch, then you might want to
make sure you exclude any arrays or other complex data types/objects from
your comparison. Please see http://www.aspfaq.com/2524

If I remember well it was something like that yes. It could happen with one
session, but at the same moment another session would not have a problem. It
did not happen often, but it was very anoying when it did. I'll implement
the code.
 
C

Cecil Westerhof

Cecil Westerhof said:
If I remember well it was something like that yes. It could happen with
one session, but at the same moment another session would not have a
problem. It did not happen often, but it was very anoying when it did.
I'll implement the code.

That solved the problem. For one reason or another the programmer that wrote
the application used session to store two objects that where only used in
the current program. So I would think that you do not need a session
variable for this. One was set to nothing (but to late) and the other was
ignored. So I inserted everywhere where the programs could be exited a
Session.Contents.Remove.
 

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

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top