| |
Storing Information in the Session
Object |
|
| |
|
An interesting feature of the
Session object is that it supports a dynamic associative array that
can be used to store named instances of data. This data can be simple
data types, scalar variables and object references. A script simply
assigns a value to a named entry in the array:
Session("User")="Jules"The preceding example
stores the string "Jules" in the Session object with the identifying
name "User." Likewise, object references are stored using the VBScript
keyword SET:
Set Session("PR") = Server.CreateObject("PR.Calculate")
Value can be retrieved from the Session object by referencing the
Session object by name, as in the following: Welcome <% =
Session("User") %>!
Or
<% Response.Write Session("PR").Name %>Note
that before you store an object reference in the Session
object, you should know what threading model it uses. Only objects
marked as both free- and apartment-threaded can be stored in the
Session object without locking the session to a single thread.
|
|
|
|
|
ASP Sessions and
the Session Object
To implement consistent user sessions on the Web, ASP provides a
flexible solution that requires no special programming. The Session objec.,
one of the intrinsic objects
supported by ASP, provides the developer with a means
of storing and retrieving data as well as performing session-related
functions.
ASP automatically creates a Session object
when a browser requests a page from an
application that does not already
have a session. When ASP creates a Session object, the user�s �session�
begins. By default, the session lasts for twenty minutes, if no
activity occurs within that
timeframe,.
ASP destroys
the session. This period can
be adjusted by setting the Timeout property of the Session object. |
| |
How ASP
Keeps Track |
|
| |
|
The Session object maintains these name/value
pairs for the lifetime of a user's logical session. For each ASP page
requested by a user, the Session object preserves the information in
the server�s memory.
To locate this information, ASP uses a unique session
identifier to match user requests with the information specific to
that user's session. Session identifiers are simply globally unique
identifiers (GUIDs) generated by ASP using the Windows API.
Session State and Cookies
ASP uses HTTP cookies to store and
maintain Session Ids in the context of the client browser. For
example, an ASP application with an established session would include
a Set-Cookie header in the HTTP Response such as:
Set-Cookie:
ASPSESSIONID=AXXQGHSSWQAJPUYT; path=/MyASPApp
The browser returns this cookie with each request made to the
virtual web application directory /MyASPApp, giving ASP the
opportunity to find the session-specific data previously stored.
It�s important to note that the Session ID cookie contains no
expiration time; therefore, it is only valid as long as the browser
remains active. |
|
|
|