Question about session objects and condition...

J

June Moore

Hi,

I've got the following code that sets a session object.
set obj = server.createobject("Scripting.Dictionary")
set session("testobj") = obj

If I want to remove the session object, do each of the following does
the same job? Which one is the best?
1 --> set session("testobj") = null
2 --> set session("testobj") = nothing
3 --> Session.Contents.Remove("testobj")

If I want to check if the session object is not exist, which is the
best option?
1 --> if (session("testobj") = null) then ...
2 --> if (session("testobj") = nothing) then ...
3 --> if (isobject(session("testobj"))) then ...

Any suggestions are welcome...

Thanks,
June...
 
R

Roland Hall

: Hi,
:
: I've got the following code that sets a session object.
: set obj = server.createobject("Scripting.Dictionary")
: set session("testobj") = obj
:
: If I want to remove the session object, do each of the following does
: the same job? Which one is the best?
: 1 --> set session("testobj") = null
: 2 --> set session("testobj") = nothing
: 3 --> Session.Contents.Remove("testobj")

It is my understanding in ASP 3.0 the first two zero out the value but do
not remove the object.
http://www.aspfaqs.com/webtech/102900-1.shtml

Before you start storing objects in session variables, you should read the
following:
http://www.learnasp.com/learn/sessionoverview.asp

To remove all session objects: Session.Abandon

: If I want to check if the session object is not exist, which is the
: best option?
: 1 --> if (session("testobj") = null) then ...
: 2 --> if (session("testobj") = nothing) then ...
: 3 --> if (isobject(session("testobj"))) then ...

if session("testobj") = "" then ...

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=74
http://www.microsoft.com/windows200...indows2000/en/server/iis/htm/asp/iiapsess.htm
http://www.w3schools.com/asp/asp_sessions.asp

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
B

Bob Barrows [MVP]

June said:
Hi,

I've got the following code that sets a session object.
set obj = server.createobject("Scripting.Dictionary")
set session("testobj") = obj

If I want to remove the session object, do each of the following does
the same job? Which one is the best?
1 --> set session("testobj") = null
2 --> set session("testobj") = nothing
3 --> Session.Contents.Remove("testobj")

2 is best
If I want to check if the session object is not exist, which is the
best option?
1 --> if (session("testobj") = null) then ...
2 --> if (session("testobj") = nothing) then ...
3 --> if (isobject(session("testobj"))) then ...

Again, 2 works fine, but ...
Any suggestions are welcome...


Just to reinforce Roland's message: the Dictionary object is NOT safe to
store in Session or Application. Doing so WILL impair your server's
performance. If you absolutely must store a data structure more complex than
an array in session, consider using an XML free-threaded DomDocument, which,
as the name implies, is free-threaded, and is therefore a good choice to
store in Session/Application. You can find the documentation for this at
msdn.microsoft.com/library.

With ASP.Net, the restriction about storing objects in session disappears,
so you may wish to consider taking that leap.

Bob Barrows
 

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
474,159
Messages
2,570,879
Members
47,417
Latest member
DarrenGaun

Latest Threads

Top