ASP Session Object

The Session object is used to store information about a user session (session) or modify related settings. Variables stored in the session object contain information about a single user, and this information is available on all pages within the session.

Example

Set and return LCID
This example demonstrates the 'LCID' property. This property sets and returns an integer indicating the location or region. Similar content such as date, time, and currency should be 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 example sets and returns the session timeout time (in minutes).

Session object

When you are operating an application, you start it, make some changes, and then close it. This process is similar to a conversation (Session). The computer knows who you are. It also knows when you start and close the application. However, on the Internet, a problem arises: web servers do not know who you are or what you are doing, as HTTP addresses cannot retain state (information).

ASP solves this problem by creating a unique cookie for each user. The cookie is sent to the server 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's session (session) or modify related settings. Variables stored in the session object hold information about a single user and are accessible on all pages in the application. Information stored in session variables is typically name, id, and parameters, etc. The server creates a new Session object for each new user and revokes this object when the session expires.

Below is the collection, properties, methods, and events of the Session object:

Collection

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

Property

Property Description
CodePage Specifies the character set used when displaying dynamic content.
LCID Set or return an integer for a specified location or region. Content such as date, time, and currency will be displayed according to the location or region.
SessionID Returns a unique id for each user. This id is generated by the server.
Timeout Set or return the timeout time (in minutes) of the session object in the application.

Method

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

Event

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