Name

HttpApplicationState

Synopsis

This class provides server-side state management that is available globally across all client sessions in an ASP.NET application. Application state is not shared across multiple ASP.NET applications, or across multiple processes or multiple computers in a single application (for example, proxy load balancing in a web farm can thwart this type of state management).

The HttpApplicationState class exposes a name/value collection of items that can store simple value types or instances of .NET objects. A single instance of the class is created automatically the first time a client requests a page in the ASP.NET virtual directory. A reference is provided through the built-in Application object.

The HttpApplicationState class combines two state collections: Contents and StaticObjects. The StaticObjects collection contains the application state objects that are defined in the global.asax file with <object runat=server> tags. This collection is immutable. The Contents collection contains all the state objects added at runtime.

The Item collection is the default indexer for HttpApplicationState, so you can use the name of a state object as an index, as in: Application("globalcounter") = 1. If you assign a value to a state object that does not exist, it is created automatically. Items are stored as the generic System.Object type and must be cast to the appropriate types when you retrieve them.

Multiple clients or threads can access application state values ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.