The session object allows you to store this information and access it from the different pages on your site so you do not have to be concerned with passing this information from page to page as you would with a typical query string or form data. The session object remains available until the session expires (20 minutes by default) or you programmatically abandon the session variable. Since HTTP does not maintain state across pages, we can use the session object to store information. 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. As previously mentioned, information stored in the Session object holds information about one single user and is available to all pages in one application. Common information stored in session variables are name, id, and preferences. The server creates a new Session object for each new user and destroys the Session object when the session expires. The Session object‘s collections, methods, properties, and events are as follows:

Collections

Methods

Properties

Events

Examples

Store and Retrieve Session Variables

The most common uses for the session object are to store and retrieve information. You create and/or modify session variable information by specifying the variable name within quotes. If you assign string data to the session, encapsulate that data in quotes as well. If you want to assign numeric data, quotes are not needed.

Remove Session Variables

You can easily remove one variable from the Contents collection or all of the variables using one command. Use either the Remove or RemoveAll method.

Session Timeout

The default timeout for a user session is 20 minutes of inactivity. This interval can be changed using the Timeout Property. In addition, you can abandon the session using the Abandon method.

Global.asa Events

In this next example, we can use the Session_OnStart and Session_OnEnd events (defined in the Global.asa file) to maintain a count of the active users accessing our web server. In your ASP page: