Article ID: 175167 - Last Review: March 9, 2007 - Revision: 3.1 How To Store State in Active Server Pages ApplicationsThis article was previously published under Q175167 On This PageSUMMARY 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. MORE INFORMATIONSession and Application VariablesHow 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.Pros
Cons
SampleSet the value of a Session variable:CookiesHow 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. Pros
Cons
SampleStore information in a cookie:Hidden Form FieldsHow 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.Pros
Cons
SampleStore information in hidden fields:QueryStringHow does it work?When you use the QueryString collection, the variables are stored in the URL as a name-value pair. For example:Pros
Cons
SampleStore information in the QueryString:File and DatabaseHow 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:
Pros
Cons
REFERENCES For more information, see the following articles on the
Microsoft Developer Network (MSDN): Session Object For
additional information, click the article numbers below to view the articles in
the Microsoft Knowledge Base: http://msdn2.microsoft.com/en-us/library/aa371675.aspx (http://msdn2.microsoft.com/en-us/library/aa371675.aspx) Application Object http://msdn2.microsoft.com/en-us/library/aa210897(office.11).aspx (http://msdn2.microsoft.com/en-us/library/aa210897(office.11).aspx) Cookies Response.Cookies Collection (http://msdn2.microsoft.com/en-us/library/ms524757.aspx) Request.Cookies Collection (http://msdn2.microsoft.com/en-au/library/ms525394.aspx) QueryString http://msdn2.microsoft.com/en-us/library/aa196462(office.11).aspx (http://msdn2.microsoft.com/en-us/library/aa196462(office.11).aspx) 244465
(http://support.microsoft.com/kb/244465/EN-US/
)
How To Disable ASP Session State in Active Server Pages
178037
(http://support.microsoft.com/kb/178037/EN-US/
)
PRB: Session Variables Lost When ASP is Located in Frameset
For 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/search/default.aspx?qu=vinterdev
(http://support.microsoft.com/search/default.aspx?qu=vinterdev)
| Article Translations
|


Back to the top
