Contents collection contains
objects and values set by the ASP-like or ScriptGen raw scripts belonging to a particular
ALP application. ASP-like scripts share the same Session object with the raw scripts.
Session.Contents(key_name) = variable
variable = Session.Contents(key_name)
Session(key_name) = variable
variable = Session(key_name)
Second syntax is recommended (see remarks below).
key_name - string that is used as label for the
value/object being set/retrieved to/from the collection.
variable - any variable that can be converted to a value
such as number and string or object. Object being set can not be an internal scripting
object! Note (most important for the JScript programmers): If you want to save array in
the collection use safearray (often called VBArray). See remarks section for more details.
If key_name does not exist in the collection VT_NULL is returned. Most
script languages support the null values: in JScript it is the keyword
null in VBScript IsNull function can be used.
Second syntax depends on the Value indexed property of the Session object
and automatically adds new key when assigning a value to non-existing key_name. The first
syntax does not allow assignment to a non-existing key_name and this will cause an error.
<% Session("UserName") = strUser %>
Set obj = Server.CreateObject("Company.SomeObject")
Session("TheObject") = obj
Contents collection is implemented using the VarDisctionary collection
object form the newObjects collections. Thus it supports all the methods and properties of
the VarDictionary. Using these methods and properties on the Contents collection gives
extended features but makes the script incompatible with the IIS ASP - it is recommended
developers targeting compatibility with ASP to limit their usage of the Session.Contents
to the features available on the both platforms.
Important for the values and objects added to the Contents collection is
their life scope. All the objects must be page script independent. The page script is
unloaded with after completing the request and in that case all objects defined internally
in the script will be no longer available. You may add to the Contents collection
primitive types as string and numeric types and objects created using Server.CreateObject method.
The Contents collection is implemented using the VarDictionary
object and you can use its methods to perform extended operations such
as Remove element, Clear all the elements, Clone the collection and save
it in a new variable and so on.
Applies to: Session object