The web server automatically creates a Session object when a web
page from the application is requested by a user who does not already
have a session. The server destroys the session object when the session
expires (timeout) or is abandoned.
You can use the Session object to store information needed for particular
user-session. Variables stored in the Session object are not discarded
when the user jumps between pages in the application; instead, these
variables persist for the entire user-session.
One common use the session object is to store user preferences.
For example, if a user indicates that they prefer not to view graphics,
you could store that information in the Session object.
Note Session state is only maintained for browsers that support
Contents: Contains the items that your have added
to the session with script commands
StaticObjects: Contains the objects created
with the tag and given session scope.
CodePage: The codepage that will be used for symbol mapping. It
is an integer, read/write. The codepage is the numeric value of the
character set, and different languages and locales may use different
code pages. For example, ANSI codepage 1252 is used for American
LCID: The locale identifier. The LCID is a standard international
abbreviation that uniquely identifies the locale.
SessionID: returns the session identification for
this users, which is generated by the server when the session is
Timeout: The timeout period for the session state
for this application, in minutes.
Abandon: This method destroys a Session object and releases its
Scripts for the following events are declared in the global.asa
You can store values in the Session object. Information stored in
the Session object is available throughout the session and has session
Example: Session variable
Saving the following code to SessionTest.asp, refresh the page couple
of times. Each time you should see different output.
if tAccessTime="" then
Response.Write("This is the first time this page has been accessed!")
Response.Write("This page was last accessed at " & tAccessTime
Declaring Session Objects in global.asa
If you sore an object in the Session object and use VBScript as
your primary scripting language, you must use the Set keyword. This
is illustrated in the following script.
<% Set Session("Obj1") = Server. CreateObject("MyComponent.class1")%>
You can then call the methods and properties exposed by MyComponent.class1
on subsequent web pages, by using the following:
Or by extracting a local copy of the object and using the following.
Set MyLocalObj1 =Session("Obj1")
Storing Arrays in the Session Object
As with the Application Object, you should not set Array values
directly in the Session object. The array should be copied to a local
variable, assignment done and then the entire array copied back to
the Session Object. Please referrer on "Storing arrays in the