how to use application variable in asp.net

/
0 Comments

Application variable is available to all classes in an ASP.NET application. Application state is stored in memory on the server and is faster than storing and retrieving information in a database. Unlike session state, which is specific to a single user session, application state applies to all users and sessions.

Create application variable

Application["Message"] = "Welcome to the Contoso site.";

it shows how you can set the application variable Message to a string.

Application variable when the application starts

Application["Message"] = "Welcome to the site.";
Application["PageRequestCount"] = 0;

it shows how you can set the application variable Message to a string and initialize the variable PageRequestCount to 0.

Application variable with locking

Application.Lock();
Application["PageRequestCount"] = ((int)Application["PageRequestCount"])+1;
Application.UnLock();

it shows how you can lock and unlock application variable. The code increases the PageRequestCount variable by 1 and then unlocks application variable.



You may also like

No comments:

Powered by Blogger.