In this blog post, we will talk about how you can beat the web.config 250k limit by splitting up your web.config into a number of subfiles.
Not only can the discussed method be helpful in beating the 250k limit, it can also help when swapping out config’s based on environments, as an example you could have one config setup with a connection string for your development setup and another for your production environments.
Splitting your web.config
To help us split up our config files we will be using the configSource option within the web.config file, below is a very basic web.config which has it’s own file setup for the connection string:
<?xml version='1.0' encoding='utf-8'?> <configuration> <connectionStrings configSource="connections.config"/> </configuration>
Now as well as the web.config file, we also have a file named connections.config, this is where the connection string details are stored, an example of this can be seen below:
<?xml version="1.0"?> <connectionStrings> <add name="SiteSqlServer" connectionString="Data Source=HOSTNAME;Initial Catalog=DATABASENAME;User ID=USERLOGIN;Password=PASSWORD" providerName="System.Data.SqlClient"/> </connectionStrings>
The above method can be used for the other sections of the web.config file as well.
Rate this post