Cannot read configuration file because it exceeds the maximum file size

55 21 20 Reputation points
2023-03-26T15:56:01.72+00:00

Is there a size limit for the iis web.config file?

I got this error when I had many redirect rules in web.config, If I remove these rules it will work normal.

Internet Information Services
0 comments No comments
{count} votes

Accepted answer
  1. Sam Wu-MSFT 7,446 Reputation points Microsoft Vendor
    2023-03-27T03:03:45.6+00:00

    @55 21

    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
    
    

    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" />
    
    

    Reference documents: Web.config file maximum size and count


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.