|
The ASP Session Object allows you to keep information specific to each of your site's visitors. Information like username, shopping cart, and location can be stored for the life of the session so you don't have to worry about passing information page to page. Variables stored in a 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.
ASP Session ID:
The ASP Session ID is the unique identifier that is automatically created when a Session starts for a given visitor. Here is an example to store user’s SessionID to a variable.
<%
DIM uSessionID
uSessionID=Session.SessionID
%>
Session Time Out:
The default session timeout period is 20 minutes. If a user has not requested or refreshed the page, session will expire. You can set this timeout by using session Timeout property.
<%
Session.Timeout=40
%>
Now session timeout period is 40 minutes.
Storing Session Variables:
Below is the example to store values in session variables.
<%
Session("username")="james"
Session("level")="member"
%>
Retrieve Session Variables
<%
response.Write(Session("username"))
response.Write("<br>")
response.Write(Session("level"))
%> |