N
Nedim
Guest
Web.config file includes of crucial information for your website to work such as server and application specific settings. Depending on your website and environment, this file can grow quickly. IIS refuses to read it if it exceeds a threshold. This check is in place to prevent possible vulnerability attacks.
Maximum size for web.config file
The default maximum limit is 250 KB. You can change this value by editing the registry key below (Reference). Make sure to restart the server after this change.
HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB
It’s a (REG_DWORD) type. More information about this key is here.
If 32-bit is enabled for your application pool, make sure to edit the following key instead:
HKLM\SOFTWARE\Wow6432Node\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB
Is there a better way to manage big web.config file?
Yes. Instead of growing the file size, it’s better to separate the configuration into multiple files. Let’s look at two scenarios.
Extensive amount of URL Rewrite rules
If you have hundreds of URL Rewrite rules, you can create rewrite maps and store them in a separate file.
Let’s say you have a rewrite map like the one below. Save it in a file called rewritemaps.config.
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/fromthisURL" value="/tothisURL" />
<add key="/fromthisURL2" value="/tothisURL2" />
</rewriteMap>
</rewriteMaps>
Then refer it from your web.config file:
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps configSource="rewritemaps.config"><rewriteMaps>
<rule name="Redirect rule">
...
</rule>
</rewrite>
</system.webServer>
</configuration>
You can store rewrite rules themselves in a separate file as well:
<rules configSource="rewriteRules.config" />
Just like web.config file, rewritemaps.config and rewriteRules.config files have 250 KB size limit as well.
Is it a good idea to have hundreds of URL rewrite rules or maps in config files? For performance, redirection by using URL Rewrite rules is better as the requests will be redirected before they are handled by ASP.NET handler. For maintenance, it’s better to do redirection and manage URLs in database so config files won’t need to be edited often.
Extensive amount of application settings
If you need to add enormous amount of settings into your config file, you can use multiple web.config files.
In the example below, application settings and connecting strings are stored in separate config files. Here is how they are referenced from the main web.config:
<appSettings configSource="appSpecific.config">
</appSettings>
<connectionStrings configSource="databaseSpecific.config">
</connectionStrings>
Maximum count for web.config files
Based on my research, there is no theoretical limit. However, CPU and memory usage can play a factor when there are too many config files mapped.
Continue reading...
Maximum size for web.config file
The default maximum limit is 250 KB. You can change this value by editing the registry key below (Reference). Make sure to restart the server after this change.
HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB
It’s a (REG_DWORD) type. More information about this key is here.
If 32-bit is enabled for your application pool, make sure to edit the following key instead:
HKLM\SOFTWARE\Wow6432Node\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB
Is there a better way to manage big web.config file?
Yes. Instead of growing the file size, it’s better to separate the configuration into multiple files. Let’s look at two scenarios.
Extensive amount of URL Rewrite rules
If you have hundreds of URL Rewrite rules, you can create rewrite maps and store them in a separate file.
Let’s say you have a rewrite map like the one below. Save it in a file called rewritemaps.config.
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/fromthisURL" value="/tothisURL" />
<add key="/fromthisURL2" value="/tothisURL2" />
</rewriteMap>
</rewriteMaps>
Then refer it from your web.config file:
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps configSource="rewritemaps.config"><rewriteMaps>
<rule name="Redirect rule">
...
</rule>
</rewrite>
</system.webServer>
</configuration>
You can store rewrite rules themselves in a separate file as well:
<rules configSource="rewriteRules.config" />
Just like web.config file, rewritemaps.config and rewriteRules.config files have 250 KB size limit as well.
Is it a good idea to have hundreds of URL rewrite rules or maps in config files? For performance, redirection by using URL Rewrite rules is better as the requests will be redirected before they are handled by ASP.NET handler. For maintenance, it’s better to do redirection and manage URLs in database so config files won’t need to be edited often.
Extensive amount of application settings
If you need to add enormous amount of settings into your config file, you can use multiple web.config files.
In the example below, application settings and connecting strings are stored in separate config files. Here is how they are referenced from the main web.config:
<appSettings configSource="appSpecific.config">
</appSettings>
<connectionStrings configSource="databaseSpecific.config">
</connectionStrings>
Maximum count for web.config files
Based on my research, there is no theoretical limit. However, CPU and memory usage can play a factor when there are too many config files mapped.
Continue reading...