Monday, January 23, 2012

Application State


ASP.NET provides application state via the HttpApplicationState class as a method of storing global application-specific information that is 

visible to the entire application. Application-state variables are, in effect, global variables for an ASP.NET application.

You can store your application-specific values in application state, which is then managed by the server.

Data that is shared by multiple sessions and does not change often is the ideal type of data to insert into application-state variables.


Session["FirstName"] = TxtFirstName.Text;

ArrayList stockPicks = (ArrayList)Application["StockPicks"];
Application["StockPicks"] = stockPicks;


Advantages of Application State:

1: Simple implementation. Application state is easy to use, familiar to ASP developers, and consistent with other .NET Framework classes.
2: Application scope. Because application state is accessible to all pages in an application, storing information in application state can mean keeping only a single copy of the information (for instance, as opposed to keeping copies of information in session state or in individual pages).

Disadvantages of Application State:

1: Application scope. The scope of application state can also be a disadvantage. Variables stored in application state are global only to the particular process the application is running in, and each application process can have different values. Therefore, you cannot rely on application state to store unique values or update global counters in Web-garden and Web-farm server configurations.                            
2: Limited durability of data. Because global data that is stored in application state is volatile, it will be lost if the Web server process containing it is destroyed, such as from a server crash, upgrade, or shutdown.
3: Resource requirements. Application state requires server memory, which can affect the performance of the server as well as the scalability of the application.

No comments: