How to Access AppSettings in Code Behind File

Waqas Anwar
10 December 2010
7758 Views

You have web application settings in the section of your web.config, and you want to access them in code behind file programmatically. You can use AppSettings property defined in System.Web.Configuration.WebConfigurationManager class as shown in the code below.

Suppose you have a setting in web.config
<appSettings>
  <add key="ApplicationName" value="EzzyLearning.com" />
</appSettings>

You can read setting in aspx or ascx file as follows:
string applicationName = WebConfigurationManager.AppSettings["ApplicationName"];
Note: You need to add the System.Configuration assembly reference in your project to use the above code. and you need to import the System.Web.Configuration namespace on topic of your code.