ASP.NET Application State and Application Variables

Asp.NET Application State allows you to persist data across all users in the entire application. Application variables can be used to store commonly used data such as connection strings. Fro example:

Application("ConnectionString") = "connectionString"

This application variable can then be referenced later anywhere in the application:

SqlConnection conn = new SqlConnection(Application("ConnectionString")

Note however that application state is all cleared on an application restart (which can be a server reboot, change to the web.config or when the application has no current users). Thus you should place the application variable setups in the Application_Start event of the Global.asax file.

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>