ASP.NET Sever Side State Management

1. Application Object

The Application object provides a mechanism for storing data that is accessible to all code running within the Web application,The ideal data to insert into application state variables is data that is sharedby multiple sessions and does not change often.. And just because it is visibleto the entire application, you need to used Lock and UnLock pair to avoid having conflit value.


2. Session Object

The Session object can be used for storing session-specific information that needs to be maintained between server round trips and between requests for pages. Session object is per-client basis, which means different clients generate different session object.The ideal data to store in session-state variables is short-lived, sensitive data that is specific to an individual session.

Each active ASP.NET session is identified and tracked using a 120-bit SessionID string containing URL-legal ASCII characters.SessionID values are generated using an algorithm that guarantees uniqueness so that sessions do not collide,and SessionID’s randomness makes it harder to guess the session ID of an existing session.
SessionIDs are communicated across client-server requests either by an HTTP cookie or amodified URL, depending on how you set the application’s configuration settings.So how to set the session setting in application configuration? Ok, let’s go further to look at it.

Every web application must have a configuration file named web.config, it is a XML-Based file, there is a section name ‘sessionState’, the following is an example:

<sessionState mode=”InProc”stateConnectionString=”tcpip=″ sqlConnectionString=”datasource=;user id=sa;password=” cookieless=”false” timeout=”20″/>

‘cookieless’ option can be‘true’ or ‘false’. When it is‘false’(default value), ASP.NET will use HTTP cookie to identify users. When it is ‘true’, ASP.NET will randomly generate a unique number and put it just right ahead of the requested file, this number is used to identify users, you can see it on the address bar ofIE:


Ok, this is enough, let’s go back to the session object.

//to store information
//to retrieve information

3. Database

Database enables you to store large amount of information per taining to state in your Web application.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>