title: HTTP Error 500.19 in IIS 8 when system.web configuration is present in apphost config
body: <p>We have a utility that automatically sets up ASP.NET web applications upon install on customer servers. This utility traditionally adds a number of configurations to the Location path for the new app in applicationHost.config. We do this programmatically using the Microsoft.Web.Administration configuration classes.</p>
  
  <p>This works fine in IIS 7.0 and IIS 7.5, but when we try to install the identical configuration in IIS 8 (Server 2012), we start getting 500.19 server errors for everything hosted on the server because of a supposedly malformed XML element (HRESULT 0x8007000d). I systematically went through all of the configuration we install, and it appears to be the the system.web/httpRuntime maxRequestLength attribute (see below). It appears that the system.web configuration element itself is the culprit, as the error does not disappear until it itself is removed.</p>
  
  <p>I've confirmed that the section definition for system.web/httpRuntime states that it is allowed Everywhere, and you can set system.web configuration at other levels of the configuration (e.g., web.config) without issue. Why can't we set it in applicationHost.config?</p>
  
  <pre><code>&lt;location path="Default Web Site/ManagementConsole"&gt;
      &lt;!-- ... more config ... --&gt;
      &lt;system.web&gt;
          &lt;httpRuntime maxRequestLength="10240" /&gt;
      &lt;/system.web&gt;
  &lt;/location&gt;
  </code></pre>
  
  <p>Edit: I noticed after the original post that the file the 500.19 error referenced was a temporary app pool config file (C:\inetpub\temp\apppools\apppoolname\apppoolname.config. The content of that file is:</p>
  
  <pre><code>&lt;!-- ERROR: There's been an error reading or processing the applicationhost.config file.  Line number: 905  Error message: The configuration section 'system.web' cannot be read because it is missing a section declaration
  --&gt;
  </code></pre>
  
  <p>But when I go into applicationHost.config and add a section group definition for system.web and a section definition for httpRuntime, the message in the 500.19 changes to claiming that there is a duplicate system.web/httpRuntime definition! So I can't define it, and I can't not define it. What??</p>