How to fix – Cannot read configuration file because it exceeds the maximum file size

This is more of a quick how article than a blog article. However, I think it is useful. We often deal with a big web.config file in Sitecore application. I have seen the following error in some Sitecore applications due to big config file.

Cannot read configuration file because it exceeds the maximum file size

This happens when the size of the web.config file exceeds 250 KB. Microsoft added this file size restriction to prevent attacker from uploading large config file to the server and start a possible Denial of Service (DOS) attack.

There are two ways to fix this issue (my choice is Option 2).

Option 1

Microsoft provided a Registry key for changing this size limit. You can change the following registry key to increase the size.

HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB  (REG_DWORD)

If you are using 64 bit OS you might have to set the registry key in the following location.

HKLM\SOFTWARE\Wow6432Node\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB (REG_DWORD)

You may find (most probably) that the key doesn’t exist. you have to create one. After creating the key you need to reset IIS before you can see the effect of the new value.

Option 2

The config file size limit is for per file. The second option is to break the web.config file into more than one config file and use the reference to the second config file from the main file. For example, I can take everything included inside the <Sitecore></Sitecore> element and create a file called sitecore.config and then make reference to the this file from the web.config like below.

<sitecore configSource=”App_Config\sitecore.config” />

App_Config is the folder where I placed the sitecore.config.

I like this solution better than the Option 1 because, because changing registry key applies for all the websites. Where as, this option is only for the website for which I am making the changes. It is more secure too, as I don’t have to mess up with the size limit imposed by Microsoft. Only problem with this option is when the sitecore.config size is bigger than 250KB. In that case we can choose Option 1 or combination of Option 1 & 2.


About Himadri Chakrabarti

I am a software developer architect and a Sitecore MVP. My professional interest is everything and anything related to Software Architecture, .NET, Sitecore, Node.js, NoSQL etc. Outside of my profession, I am a hobbyist photographer. Link to my photography site
This entry was posted in deugging, Sitecore and tagged , , , . Bookmark the permalink.

6 Responses to How to fix – Cannot read configuration file because it exceeds the maximum file size

  1. Sitecore recommended practice is to use “your” option 2 , and always keep your changes in separate config files in the app_config folder.

  2. mawkstiles says:

    I’ve had trouble with this solution. Not because anything you’ve done was wrong, but because I’m using transform config files. The publish process can’t merge the files because the include configs aren’t combined at that point. Meaning you can’t override settings in a config file that lives under /App_Config/Include.

    I was able to move other parts of the config to separate files like the section though which was enough to bring the file size down and get it running.

  3. Jason St-Cyr says:

    This Option 2 just saved me during a Sitecore 8 upgrade. Sitecore 8’s Web.config has grown to 241KB of the allowed 250KB. This doesn’t leave a lot of room for customizations in the configuration file. Existing clients running off older versions (6.x) had more room (about 40KB) instead of the 9KB Sitecore 8 gives you. That’s a lot of room lost.

  4. Pingback: Sitecore 8 Upgrades: ‘Cannot read configuration file because it exceeds the maximum file size’ | Agile and ALM

  5. Abhishek S says:

    Thank you. That resolved my issue.

  6. Pingback: Sitecore configuration moved in Sitecore 8.1 - Kayee

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s