News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

ASP Session Object

Started by VelMurugan, Dec 16, 2008, 07:23 AM

Previous topic - Next topic

VelMurugan

ASP Session Object

The Session object is used to store information about, or change settings for a user session. Variables stored in the Session object hold information about one single user, and are available to all pages in one application.

The Session object

When you are working with an application, you open it, do some changes and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end.

But on the internet there is one problem: the web server does not know who you are and what you do because the HTTP address doesnt maintain state.

ASP solves this problem by creating a unique cookie for each user. The cookie is sent to the client and it contains information that identifies the user. This interface is called the Session object.

The Session object is used to store information about, or change settings for a user session. Variables stored in the Session object hold information about one single user, and are 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.

When does a Session Start?

A session starts when:

A new user requests an ASP file, and the Global.asa file includes a Session_OnStart procedure
A value is stored in a Session variable
A user requests an ASP file, and the Global.asa file uses the <object> tag to instantiate an object with session scope


When does a Session End?

A session ends if a user has not requested or refreshed a page in the application for a specified period. By default, this is 20 minutes.

If you want to set a timeout interval that is shorter or longer than the default, you can set the Timeout property.

The example below sets a timeout interval of 5 minutes:

<%
Session.Timeout=5
%>


To end a session immediately, you may use the Abandon method:

<%
Session.Abandon
%>


Note: The main problem with sessions is WHEN they should end. We do not know if the users last request was the final one or not. So we do not know how long we should keep the session "alive". Waiting too long for an idle session uses up resources on the server, but if the session is deleted too soon the user has to start all over again because the server has deleted all the information. Finding the right timeout interval can be difficult!

Tip: If you are using session variables, store SMALL amounts of data in them.

Source : ExpertsForge