ASP SessionObject


The Session object is used to store information about a user session, or to change settings for a user session.


Examples

Try it Yourself - Examples

Set and return LCID
This example demonstrates the "LCID" property. This property sets and returns an integer that indicates a location or region. Content such as dates, times, and currency is displayed according to the location or region.

Return SessionID
This example demonstrates the "SessionID" property. This property returns a unique id for each user. This id is generated by the server.

Session timeout
This example demonstrates the "Timeout" property. This property sets and returns the session timeout period (in minutes).


Session Object

When you operate an application on your computer, you open it, make changes, and then close it. This is very much like a session. The computer knows who you are. It knows when you open and close an application. However, on the Internet a problem arises: because HTTP addresses cannot maintain state, the Web server does not know who you are or what you have done.

ASP solves this problem by creating a unique cookie for each user. The cookie is sent to the user's computer and contains information that identifies the user. This interface is called the Session object.

The Session object is used to store information about a user session, or to change settings for a user session.

Variables stored in the Session object store information about a single user and are available to all pages in an application. Commonly, the information stored in session variables is name, id, and parameters. The server creates a new Session for each new user and destroys the Session object when the session expires.

The collections, properties, methods, and events of the Session object are described below:

Collections

Collection Description
Contents Contains all entries added to the session via script commands.
StaticObjects Contains all objects added to the session using HTML <object> tags.

Properties

Property Description
CodePage Specifies the character set to use when displaying dynamic content.
LCID Sets or returns an integer that specifies a location or region. Content such as dates, times, and currency is displayed according to the location or region.
SessionID Returns a unique id for each user. This id is generated by the server.
Timeout Sets or returns the timeout period (in minutes) for the Session object in the application.

Methods

Method Description
Abandon Abandons a user's session.
Contents.Remove Deletes an item from the Contents collection.
Contents.RemoveAll() Deletes all items from the Contents collection.

Events

Event Description
Session_OnEnd This event occurs when a session ends.
Session_OnStart This event occurs when a session begins.

Other Extensions