Create Web.config

If you web site doesn’t have Web.config file, you can create one

  • Using Visual Studio: Right click on your web site > Add > Add New Item… > Web Configuration File > Web.config
  • Manually: Create a text file and change name to Web.config at your web site root folder

Add application settings (key-value pair)

Open Web.config

<?xml version=”1.0″?>
<configuration>

<appSettings>
<add key=”KeyName1″ value=”KeyValue2″/>
<add key=”KeyName2″ value=”KeyValue2″/>

</appSettings>
</configuration>

Read application settings

  1. Add:
    using System.Web.Configuration;
  2. Codes:
    var key1 = WebConfigurationManager.AppSettings[“KeyName1”];
    var key2 = WebConfigurationManager.AppSettings[“KeyValue2”];