0% found this document useful (0 votes)
30 views2 pages

Managing State

Application state in ASP.NET allows for storing and retrieving data globally for all users of a web application. Data stored in application state is available to all users and persists in server memory. Application state is commonly used to store counters, application data like tax rates, and track site visitors. The HttpApplicationState class provides methods to add, remove, and access items stored in application state. Events like Application_Start and Application_End can be used to write and read from application state.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Managing State

Application state in ASP.NET allows for storing and retrieving data globally for all users of a web application. Data stored in application state is available to all users and persists in server memory. Application state is commonly used to store counters, application data like tax rates, and track site visitors. The HttpApplicationState class provides methods to add, remove, and access items stored in application state. Events like Application_Start and Application_End can be used to write and read from application state.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

22/11/2022, 06:04 ASP.

NET - Managing State

Application State
The ASP.NET application is the collection of all web pages, code and other files within a single
virtual directory on a web server. When information is stored in application state, it is available to all
the users.

To provide for the use of application state, ASP.NET creates an application state object for each
application from the HTTPApplicationState class and stores this object in server memory. This
object is represented by class file global.asax.

Application State is mostly used to store hit counters and other statistical data, global application
data like tax rate, discount rate etc. and to keep the track of users visiting the site.

The HttpApplicationState class has the following properties:

Properties Description

Item(name) The value of the application state item with the specified name. This
is the default property of the HttpApplicationState class.

Count The number of items in the application state collection.

The HttpApplicationState class has the following methods:

Methods Description

Add(name, value) Adds an item to the application state collection.

Clear Removes all the items from the application state collection.

Remove(name) Removes the specified item from the application state collection.

RemoveAll Removes all objects from an HttpApplicationState collection.

RemoveAt Removes an HttpApplicationState object from a collection by index.

Lock() Locks the application state collection so only the current user can
access it.

Unlock() Unlocks the application state collection so all the users can access it.

Application state data is generally maintained by writing handlers for the events:

Application_Start
Application_End
Application_Error
Session_Start
Session_End

https://www.tutorialspoint.com/asp.net/asp.net_managing_state.htm 1/2
22/11/2022, 06:04 ASP.NET - Managing State

The following code snippet shows the basic syntax for storing application state information:

Void Application_Start(object sender, EventArgs e)

Application["startMessage"] = "The application has started.";

Void Application_End(object sender, EventArgs e)

Application["endtMessage"] = "The application has ended.";

https://www.tutorialspoint.com/asp.net/asp.net_managing_state.htm 2/2

You might also like