Recently, I’ve been spending my time working on upgrading a site to Sitecore 8 and I encountered the dreaded 250KB limitation for the Web.config file. For security reasons, IIS will throw the “Cannot read configuration file because it exceeds the maximum file size” error if a single .config file exceeds 250KB.
What is different about Sitecore 8?
This problem isn’t new to Sitecore 8. Any version of Sitecore could potentially go beyond the 250KB limit for the configuration file. However, Sitecore 8 has grown the default Web.config to 241KB. That gives you only 9KB of room in this latest version, which makes it much more probable that you will encounter this error during an upgrade to Sitecore 8.
Sitecore 6.x Web.config came in at around 210KB, and version 7.x grew to around 225KB. When we do upgrades to Sitecore 8, previously working sites can now easily go over the 250KB limit if developers are relying on using the extra space available in previous releases of Sitecore.
In my scenario, the Web.config customizations included rewrite rules in the Web.config which pushed the total file size over the 250KB limit once upgraded to Sitecore 8. At this point, the entire site starts throwing the size limit error.
How to fix the error
While researching what caused the error, the following blog post was very helpful and provided two options for resolution:
“Option 2” suggests to move the customized configurations into separate files and include them using the configSource attribute into the Web.config. As long as each individual file is under 250KB, you are okay.
Looking ahead to future upgrades
I think it would be great if all the Sitecore sections could also be split out into smaller files, such as App_Config\Sitecore.config. This is already done for things like Commands and MimeTypes, so it seems like a logical extension. It would also make upgrading easier as the ‘core’ Sitecore application configurations would be in other files and not in the often-changed Web.config file.