How to Access AppSettings in Code Behind File

You have web application settings in the <appSettings> 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 following appSettings in web.config

  <add key="ApplicationName" value="" />

You can read above appSettings 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.



About author

User avatar

Waqas Anwar

Founder of, Senior Consultant, Microsoft .NET and Web Technologies