Introduction
This is a very basic ASP.NET tip about how to manage multiple Config files on one web application by dividing the specific Config settings to multiple Config files.
Background
While developing the web application, a developer prefers to keep Configuration or setting parameters in Config file. The config file size can be too big due to more configuration sections like appSetings
, configSections
, connectionStrings
, services related sections, logging sections, etc. In case of Enterprise Library Blocks, all of the configuration settings reside in .config file. This easily exceeds the config file default size limit of 250 KB. This throws the exception "Cannot read configuration file because it exceeds the maximum file size".
Solution
The solution for this issue is splitting of config file. Using this, we can specify certain sections of your web.config reside in a separate .config file. So you could have a connectionStrings.config file containing your connection strings or appSettings.config file for your appSettings
section of web.config.
Below, we have Main Config file where we have mentioned the Config source to different configuration files.
ConnectionStrings.config
Appsettings.config
Points of Interest
- Separate files can result in a more logical and modular structure for configuration files
- Easy to manage
- Settings in include file can be managed or changed at runtime without any impact