ASP Session



The Session object is used to store information about the user session (session), or to change the settings of the user session (session).


tryitimg.gif

Try it - Example

Set and return LCID
This example demonstrates the "LCID" property. This property sets and returns an integer indicating the location or region. Contents such as date, time and currency are displayed based on 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" attribute. This property sets and returns the session timeout in minutes.


Session Object

When you work on an application on your computer, you open it, make changes, and then close it. It's a lot like a conversation. The computer knows who you are. It knows when you open and close apps. However, on the Internet a problem arises: since HTTP addresses cannot maintain state, the web server has no idea who you are and what you do.

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

The Session object is used to store information about the user session (session), or to change the settings of the user session (session).

Variables stored in the Session object store information about a single user and are available to all pages in the application. The common information stored in session variables is usually name, id, and parameters. The server will create a new Session for each new user and revoke the Session object when the session expires.

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

Collection

CollectionDescription
ContentsContains all entries appended to the session via script commands.
StaticObjectsContains all objects appended to the session using HTML's <object> tag.

Properties

PropertiesDescription
CodePageSpecifies to display dynamic content The character set used.
LCIDSet or return an integer for the specified location or region. Contents such as date, time, and currency are displayed based on location or region.
SessionIDReturns a unique id for each user. This id is generated by the server.
TimeoutSets or returns the timeout (in minutes) for the Session object in the application.

Method

MethodDescription
AbandonRevoke a user's session.
Contents.RemoveRemove an item from the Contents collection.
Contents.RemoveAll()Removes all items from the Contents collection.

Event

EventDescription
Session_OnEndThis event occurs when a session ends.
Session_OnStartThis event occurs when a session starts.