C#,vb.net,MVC,Jquery,javascript,jscript,vbscript,html,vb,sharepoint,COM,WPF,WCF,Wwf,Asp,Asp.net,questions & answers,

Latest in Sports

Friday, September 5, 2014

Handling of large config file size issue

Handling of large config file size issue

 
Scenario: Have you ever come to a situation where your web.config or app.config in .net application is too large and your application is not able to handle this? If not, you are one of few lucky developers. But 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: So the question is how to overcome this issue. The answer is splitting of config file. Using this, you can specify certain sections of your web.config reside in a separate file. So you could have a connectionStrings.config file containing your connection strings or appSettings.config file for your appSettings section of web.config.
 
How to achieve this: In config file, each configuration section has "configSource" property. It gets or sets the name of the include file in which the associated configuration section is defined.

Example 1
Below is the snippet for connectionstrings section which uses configSource property to define separate config file where all the connection strings are specified.
 The new connectionStrings.config file is as below:


Example 2
See below example for appSettnigs:
 The appSettings moved to separate appSettings.config file as below:

Example 3
The original defaultProxy section in web.config is as below:
 Below is the snippet of separated proxySettings.config after moving the defaultProxy section:
and the original config file will be as below:

Advantages of splitting the config file:
Specifying a separate file can be useful in multiple ways:
·         Separate files can result in a more logical and modular structure for configuration files.
·         File-access security and permissions can be used to restrict access to sections of configuration settings.
·         Settings in an include file that are not used during application initialization can be modified and reloaded without requiring an application restart.
·         Configurations in Separate files are more manageable.

No comments:

Post a Comment