Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

ASP Session Object

The Session object stores information needed for a particular user-session.

Variables stored in the Session object are not discarded when the user jumps between pages in the application; instead, they persist for the entire user-session. The Web server automatically creates a Session object when a Web page (from a server application) is requested by a user who does not already have a session. The server destroys the Session object when the session expires or is abandoned.

The AllowSessionState registry or configuration file setting controls the creation of Session objects. If AllowSessionState is set to False, the Session object cannot be used. The default is to use Sessions.

Session object event scripts are declared in the Global.asa.

Note

Session state is only maintained for browsers that support cookies.

Syntax: ASP Session Object

Session.collection|property|method

ASP Session Object Collections

ASP Session Object Contents Collection

Contains the items you have added to the session with script commands.

ASP Session Object StaticObjects Collection

Contains items created in Global.asa using the <OBJECT> tag and given session scope.

ASP Session Object Properties

ASP Session Object SessionID Property

Returns the session identifier for this client. Each session has a unique identifier.

ASP Session Object Timeout Property

The timeout period, in minutes, for session state for this application.

ASP Session Object LCID Property

Sets or gets a Locale Identifier (LCID) that determines how certain content-such as date, time, and currency-is formatted.

The CodePage property is not currently implemented in Sun Chili!Soft ASP.

ASP Session Object Methods

ASP Session Object Abandon Method

Destroys a Session object and all objects stored in it, and releases their resources.

ASP Session Object Events

Session_OnStart

Occurs when the server creates a new session. It runs before executing the requested page.

Session_OnEnd

Occurs when the session is abandoned or times out.

Session object events are defined in the Global.asa file.

Remarks: ASP Session Object

You can store values in the Session object. Information stored in the Session object is available for the entire session and has session scope. The following script demonstrates how two types of variables are stored:

Session("username") = "Janine"

Session("age") = 42

If you are using VBScript as your scripting language, you must use the Set keyword to store an object in the Session object, as shown in the following example:

<% Set Session("Obj1") = Server.CreateObject("MyComponent") %>

You can then call the methods and properties of Obj1 on subsequent Web pages by using the following syntax:

<% Session("Obj1").MyObjMethod %>

As an alternative, you can extract a local copy of the object:

Set MyLocalObj = Session("Obj1")

MyLocalObj.MyObjMethod

You cannot store a built-in object in a Session object. Each of the following lines will return an error:

Set Session("var1") = Session

Set Session("var2") = Request

Set Session("var3") = Response

Set Session("var4") = Server

Set Session("var5") = Application

Before you store an object in the Session object, you must know what threading model it uses. Only objects marked as both free and apartment-threaded can be stored in the Session object.

The Session object is implemented as a collection. If you store an array in an Session object, you should not attempt to alter elements of the stored array directly. For example, the following script does not work:

Session("StoredArray") (3) = "new value"

Instead of storing the value "new value" in StoredArray(3), the value is stored in the Session collection, overwriting any information stored at Session(3).

See the Application object for an example of storing an array.

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.