ASP.NET MVC Web.config move AppSettings to separate file

Let’s get the appSettings inside the web.config file to a separate file for better maintenance of the code.

Step 1: Open your web.config file.

Step 2: You will see your appSettings code in there


Step 3: Create a new config file in the project name “PrivateSettings.config” and add the settings code you want to keep there.


Step 4: Add the path to your extra appSettings file to the web.config appSettings tag


Step 5: Run your application normally.

Above I mentioned “extra” because it will not neglect the settings added in the web.config but will just also consider one in the new file “PrivateSettings.config”.

Why we did this?

  • Separate code helps better maintenance of the code.
  • Easy change of the connection to database when hosting.
  • Maintain separate files for development and deployment environment.

These are just some options you can do more.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.