How to move web.config appSettings in a separate web.config file ?

In this post you will learn how to create a separate web.config file in ASP.NET or MVC to store development and production versions of application settings.

Step 1. Create a Private.config file on root with below code

<appSettings>
  <add key="data1" value="value1"/>
  <add key="data2" value="value2"/>

</appSettings>

Step 2. Open main web.config file (on application root) and then define file path with appSettings start tag, as given below

<configuration>
  ....other codes
  <appSettings file="PrivateSettings.config">
    <add key="webpages:Version" value="3.0.0.0"/>
    <add key="webpages:Enabled" value="false"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
  ....other codes

</configuration>

Step 3. That's it, now you can use data1 and data2 appsettings in your application, as given below

var data1 = ConfigurationManager.AppSettings["data1"];

var data2 = ConfigurationManager.AppSettings["data2"];

Hope this helps.

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System