ALP Application.Contents collection

Contents collection contains objects and values set by the ASP pages or ScriptGen raw scripts belonging to a particular ALP application. ASP pages share the same Application object with the raw scripts.

Syntax:

  1. Application.Contents(key_name) = variable
    variable = Application.Contents(key_name)

  2. Application(key_name) = variable
    variable = Application(key_name)

Second syntax is recommended (see remarks below).

Parameters:

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 (such as VBScript class or a Jscript object)! See remarks section for more details.

If key_name does not exist in the collection Empty is returned (if the IIS compatibility level is set to 0 - Null is returned for compatibility with ALP 1.0) .

Second syntax depends on the Value indexed property of the Application object and automatically adds new key when assigning a value to non-existent key_name. The first syntax does not allow assignment to a non-existing key_name and this will cause an error.

Samples:

<% Application("Visits") = Application("Visits") + 1 %>

<%
    Dim db
    Set db = Application.CreateObject("ADODB.Connection")
    db.Open "MYDB"
    Session("SiteDB") = db
%>

Remarks:

Contents collection is implemented using the VarDsctionary collection object form the newObjects AXPack1. 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 IIS to not use these extended features.

Important for the values and objects added to the Contents collection is their life scope. All the objects must be independent of the page script. E.g. an object from the ALP run-time library created using Server.CreateObject can be Set to an Application variable, but a VBScript class created using New operator cannot. The page script is unloaded 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.

Applies to: Application object

See also: VarDictionary , Session object

newObjects Copyright 2001-2006 newObjects [ ]