ASP Session
Object
The Session object is used to store information about a user session or to modify settings for a user session.
Try It Yourself - Examples
Session Object
When you operate an application on your computer, you open it, make some changes, and then close it. This is similar to a session. The computer knows who you are. It knows when you open and close the application. However, on the internet, the problem arises: since HTTP addresses cannot maintain state, web servers do 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 modify settings for a user session.
Variables stored in the Session object store information for a single user and are available to all pages in the application. Common information stored in session variables usually includes name, id, and parameters. The server creates a new Session for each new user and revokes the Session object when the session expires.
Descriptions of the Session object's collections, properties, methods, and events are as follows:
Collections
Collection | Description |
---|---|
Contents | Contains all items added to the session via script commands. |
StaticObjects | Contains all objects added to the session using the HTML <object> tag. |
Properties
Property | Description |
---|---|
CodePage | Specifies the character set used to display dynamic content. |
LCID | Sets or returns an integer representing a location or region. Date, time, and currency content are 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 | Revokes 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 starts. |