The ASP Session Object

The Session object is automatically created every time client browser access pages from your web site. Session object is specific for every user and varies from user to user. It can be used to store variables specific for a user and IIS will maintain these variables when the client moves across pages within your site. You can create and access Session scope variables. You can store user specific preferences within Session object such as 'font-size, background-color' etc.

Note that scripts for different Events are to be declared in global.asa file.

Syntax :


Collections Description
 Contents Contains all the items which have been added to the Session object. You can iterate through the Contents collection and retrieve a list of all the items added or you can retrieve a specific item. Note that it contains all the Session items except the ones created using <object> element. 
StaticObjects Contains all the items which have Session scope created using <object> element. As with Session.Contents collection you can iterate through the StaticObjects collection to get a list of items or you can get a specific item out of the StaticObjects collection.


Properties Description
 CodePage An integer which defines the code page to be used to display content to the client browser e.g. code page 1252 is used to for American english and most European languages and 932 is used for Japanese kanji. 
LCID Stands for locale identifier. It is a standard international abbreviation that uniquely identifies the locale e.g. LCID 2057 stands for British locale.
SessionID A long which returns the session identifier for this client browser. 
Timeout An integer which specifies a time out period in minutes. If the client doesn't refresh or request any page of your site within this time out period then the server ends the current session. If you do not specify any time out period then by default time out period is 20 minutes.


Methods Description
Abandon Destroys the current session object and releases its resources, meaning there by that if the client requests any page of your site after Session.Abandon method has been called then a separate session will be started.
Contents.Remove Deletes the given item from the Session.Contents collection.
Contents.RemoveAll Destroys all the items in the Session.Contents collection.

Events Description
Session_OnEnd This event occurs when the session is abandoned or times out for a specific user.
Session_OnStart Occurs when a new session is started. All the ASP objects are available for you to use. You can define your session wide variables here.

Back To Top
© 1998 - 2024
Version 7.21 | Advertise on this site