Search This Blog

Tuesday, 1 November 2011

Session Handling in ASP

0 comments
SESSION TRACKING IN ASP! 
Handling Session and Cookies are two different ways in which Web Server maintains information about individual clients to distinguish between them. Many web sites provide custom web pages or functionality on a client-by-client basis. For e.g., some web sites (e.g., yahoo) allow the users to customize their home page to suit their needs.
Another example of a service that is customized on a client-by-client basis is a shopping cart for shopping on the web. When a purchase is made, the server must distinguish between clients so the business can assign the proper items and charge each client the proper amount.
A third method of customization on a client-by-client basis is marketing to specific audiences. Companies often track the pages people visit so they can display advertisement based on a person’s browsing trends.
Session Tracking:
A Session is nothing but the duration of a web site in which it maintains its client’s information for the purpose of customizing its web pages for individual clients. In ASP, a session is an object maintained by the server to store its client’s information that distinguishes clients individually.
The server performs session tracking by creating a session object when a specific person visits a site. When he visits the web site the first time, the server assigns the user a unique Session ID. When the client makes additional requests to navigate to other pages of the web site, the client’s Session ID is used to keep track of him individually.
A session can be terminated in two ways: One way is to set the TimeOut property of the session object, which specifies the number of minutes that a session exists before it expires. The default value for this property is 20 minutes. Another way of terminating a session is by calling the session method Abandon.
Session Object’s Variables:
A Session object is usually used to store user preferences such as shopping habits. For e.g., if a user enters the user name on the first page on a web site, the session object may be used to store the name of the user for the rest of the session. This information is saved in a variable known as a Session Variable. Session variables continue to exist till the web server destroys the session object when the session is terminated or timed out.
The syntax to create a session variable and store a value in it is as follows:
Session (“SessionVariableName”) = value
The syntax to read a session variable is as follows:
          value = Session (“SessionVariableName”)
The following is an example which gets the user name from the user in a text box (Session1.asp) and then stores it in a session variable named uname (Session2.asp) that would be used by another web page generated by Session3.asp.

Program: Session1.asp that gets the user input

Program: Session2.asp that creates a Session variable “uname”

Program: Session3.asp that creates a dynamic web page having User Name


To know more about ASP mail me @
davidjlivingston@gmail.com 

Note:  Articles relevant to ASP may be found by following the links provided in the sidebar.

Leave a Reply