Article ID: 175167 - View products that this article applies to.
This article was previously published under Q175167
When you develop an Active Server Pages (ASP) Web application, a common way to customize the content is to store information about the user. There are several ways to store information in an ASP environment. This article lists the most common ways to store state, including sample code and the pros and cons of each option.
Session and Application Variables
How do they work?The Session and Application variables are stored on the server. A SessionID, which is generated at the start of an ASP session, is an in-memory cookie that is stored on the client to identify the Session variables. As a result, the client must have cookies enabled in the browser for Session and Application variables to work.
SampleSet the value of a Session variable:
Retrieve the value from the Session variable:
How do they work?There are two types of cookies: in-memory cookies, and cookies that are stored to the client's disk. An in-memory cookie is one or more name-value pairs that are stored in the browser's memory until the browser is closed. A cookie that is stored to disk is a file on the client's computer that contains name-value pairs.
Cookies can be set and retrieved from both client-side and server-side code.
SampleStore information in a cookie:
Retrieve the value from a cookie:
Hidden Form Fields
How do they work?Every page needs a form with hidden form fields that contain the state information. Instead of linking and redirecting to pages, the form is submitted when a user browses to a different page.
SampleStore information in hidden fields:
Retrieve the value from the hidden form field:
How does it work?When you use the QueryString collection, the variables are stored in the URL as a name-value pair. For example:
NOTE: Name-value pairs are separated by an ampersand (&).
SampleStore information in the QueryString:
Retrieve the values from the QueryString:
File and Database
How do they work?You can implement this technique in many different ways. The following steps illustrate one way to implement the file and database storing of state:
For more information, see the following articles on the Microsoft Developer Network (MSDN):
Session ObjectFor additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/244465/EN-US/ )How To Disable ASP Session State in Active Server Pages
178037For the latest Knowledge Base articles and other support information on Visual InterDev and Active Server Pages, see the following page on the Microsoft Technical Support site:
(http://support.microsoft.com/kb/178037/EN-US/ )PRB: Session Variables Lost When ASP is Located in Frameset
Article ID: 175167 - Last Review: March 9, 2007 - Revision: 3.1
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.