ASP Session Object
The Session object is used to store information about a user session, or to change the settings of a user session.
Try it - Example
Set and return the LCID
This example demonstrates the "LCID" property. This property sets and returns an integer that indicates a location or region. Things such as dates, times, and currency are displayed according to the location or region.
Return the SessionID
This example demonstrates the "SessionID" property. This property returns a unique id for each user. The id is generated by the server.
Session Timeout
This example demonstrates the "Timeout" property. This property sets and returns the timeout period (in minutes) of a session.
Session Object
When you work with an application on your computer, you open it, make some changes, and then close it. This is much like a conversation (Session). The computer knows who you are. It knows when you open and close the 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 the settings of a user session.
Variables stored in the Session object hold information for a single user and are available to all pages in an application. Common information stored in session variables is typically 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:
Union
| Union | Description |
|---|---|
| Contents | Contains all items appended to the session by script commands. |
| StaticObjects | Contains all objects appended to the session using the HTML |
property
| property | Description |
|---|---|
| CodePage | Specifies the charset used when displaying dynamic content. |
| LCID | Sets or returns an integer for a specified 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) of the Session object in the application. |
Method
| 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
| Events | Description |
|---|---|
| Session_OnEnd | This event occurs when a session ends. |
| Session_OnStart | This event occurs when a session begins. |