Karl Gjertsen

Architect, Developer, Speaker, Bad Golfer,
Raygun brand ambassador and creator of Infiniforms

Split web.config into multiple files

Having used web.config and app.config files for many years, today I learnt something new about them. You can split them into multiple files!

This can be especially handy if your configuration files are getting too big. Splitting them is very straight forward and I will show you how to move your connection strings into a new file.

Step #1:
The first thing to do is open you config file and find the <connectionString> node:

    <add name="ConnectionString1" connectionString="Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;" providerName="System.Data.SqlClient" />
    <add name="ConnectionString2" connectionString="Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;" providerName="System.Data.SqlClient" />

Step #2:
Copy this, including the <ConnectionString> tags and paste it into a notepad, then save it next to your web.config file, calling it ConnectionStrings.config

Step #3:
Update the original config file so it knows it has been split:

<connectionStrings configSource="ConnectionStrings.config" />

That’s it. Your configuration file has been split into multiple files.

%d bloggers like this: