title: Error 500 and "The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration"
body: <p>I have a .NET web application installed on a Windows Server 2008 R2 Datacenter with .NET Framework 4.0 (IIS 7.5). I have a main 4.0 app and a nested 2.0 app. I have configured IIS for each app. The 2.0 folder was converted to an app and it runs in a 2.0 app pool. The 4.0 app is the root app and it is set to run in a 4.0 app pool.</p>
  
  <p>This is the web.config of the main 4.0 app:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  &lt;configSections&gt;
  &lt;section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /&gt;
  &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" /&gt;
  &lt;/configSections&gt;
  &lt;exceptionHandling&gt;
  &lt;exceptionPolicies&gt;
    &lt;add name="LibraryPolicy"&gt;
      &lt;exceptionTypes&gt;
        &lt;add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow" /&gt;
      &lt;/exceptionTypes&gt;
    &lt;/add&gt;
  &lt;/exceptionPolicies&gt;
  &lt;/exceptionHandling&gt;
  &lt;log4net&gt;
  ...
  &lt;/log4net&gt;
  &lt;connectionStrings&gt;
  ...
  &lt;/connectionStrings&gt;
  &lt;appSettings&gt;
  ...
  &lt;/appSettings&gt;
  &lt;location inheritInChildApplications="false"&gt;
      &lt;system.web&gt;
          &lt;httpRuntime executionTimeout="300" maxRequestLength="51200" requestValidationMode="2.0" /&gt;
          &lt;authorization&gt;
              &lt;deny users="?" /&gt;              
          &lt;/authorization&gt;            
          &lt;compilation debug="false" targetFramework="4.0"&gt;
              &lt;assemblies&gt;
                  &lt;add assembly="System.Web.Mobile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /&gt;
              &lt;/assemblies&gt;
          &lt;/compilation&gt;
  
          &lt;customErrors mode="RemoteOnly" /&gt;
  
          &lt;sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" stateNetworkTimeout="10" sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI" sqlCommandTimeout="30" customProvider="" cookieless="UseCookies" cookieName="ASP.NET_SessionId" timeout="3000" allowCustomSqlDatabase="false" regenerateExpiredSessionId="true" partitionResolverType="" useHostingIdentity="true"&gt;
              &lt;providers&gt;
                  &lt;clear /&gt;
              &lt;/providers&gt;
          &lt;/sessionState&gt;
  
          &lt;authentication mode="Forms"&gt;
              &lt;forms loginUrl="public/default.aspx" name=".ABABABA" timeout="3000" /&gt;
          &lt;/authentication&gt;
  
          &lt;pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" /&gt;
  
      &lt;/system.web&gt;
  &lt;/location&gt;
  &lt;location path="app20" allowOverride="false"&gt;
      &lt;system.web&gt;
          &lt;trust level="High" /&gt;
      &lt;/system.web&gt;
    &lt;/location&gt;
  &lt;location path="ScriptResource.axd"&gt;
      &lt;system.web&gt;
          &lt;authorization&gt;
              &lt;allow users="*" /&gt;
              &lt;deny users="?" /&gt;
          &lt;/authorization&gt;
      &lt;/system.web&gt;
  &lt;/location&gt;
  &lt;location path="WebResource.axd"&gt;
      &lt;system.web&gt;
          &lt;authorization&gt;
              &lt;allow users="*" /&gt;
              &lt;deny users="?" /&gt;
          &lt;/authorization&gt;
      &lt;/system.web&gt;
  &lt;/location&gt;
  &lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;handlers&gt;
          &lt;remove name="WebServiceHandlerFactory-Integrated" /&gt;
          &lt;remove name="ScriptHandlerFactory" /&gt;
          &lt;remove name="ScriptHandlerFactoryAppServices" /&gt;
          &lt;remove name="ScriptResource" /&gt;
          &lt;add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &lt;/handlers&gt;
      &lt;urlCompression doDynamicCompression="true" /&gt;
      &lt;tracing&gt;
          &lt;traceFailedRequests&gt;
              &lt;add path="*"&gt;
                  &lt;traceAreas&gt;
                      &lt;add provider="WWW Server" areas="Rewrite" verbosity="Verbose" /&gt;
                  &lt;/traceAreas&gt;
                  &lt;failureDefinitions statusCodes="200-399" /&gt;
              &lt;/add&gt;
          &lt;/traceFailedRequests&gt;
      &lt;/tracing&gt;
      &lt;defaultDocument enabled="true"&gt;
          &lt;files&gt;
              &lt;clear /&gt;
              &lt;add value="Default.aspx" /&gt;
              &lt;add value="Index.html" /&gt;
              &lt;add value="Index.htm" /&gt;
              &lt;add value="Index.cfm" /&gt;
              &lt;add value="Index.shtml" /&gt;
              &lt;add value="Index.shtm" /&gt;
              &lt;add value="Index.stm" /&gt;
              &lt;add value="Index.php" /&gt;
              &lt;add value="Index.php3" /&gt;
              &lt;add value="Index.asp" /&gt;
              &lt;add value="Index.aspx" /&gt;
              &lt;add value="Default.htm" /&gt;
              &lt;add value="Default.asp" /&gt;
          &lt;/files&gt;
      &lt;/defaultDocument&gt;
      &lt;httpProtocol&gt;
          &lt;customHeaders&gt;
              &lt;remove name="X-Powered-By" /&gt;
              &lt;add name="X-UA-Compatible" value="IE=Edge,chrome=1" /&gt;
          &lt;/customHeaders&gt;
      &lt;/httpProtocol&gt;
      &lt;httpRedirect enabled="false" /&gt;
      &lt;rewrite&gt;
          &lt;rules&gt;
              &lt;rule name="CanonicalHostNameRule1"&gt;
                  ...
              &lt;/rule&gt;
          &lt;/rules&gt;
      &lt;/rewrite&gt;
  &lt;/system.webServer&gt;
  &lt;system.serviceModel&gt;
      &lt;bindings&gt;
          ...
      &lt;/bindings&gt;        
      &lt;client&gt;
          ...
      &lt;/client&gt;
  &lt;/system.serviceModel&gt;
  &lt;system.web&gt;
      &lt;globalization culture="es-ES" uiCulture="es-ES" /&gt;
      &lt;machineKey decryptionKey="..." validationKey="..." /&gt;
  &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And this is the web.config of the nested 2.0 app:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  &lt;configSections&gt;
      &lt;sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
          &lt;sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
              &lt;section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /&gt;
              &lt;sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
                  &lt;section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /&gt;
                  &lt;section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /&gt;
                  &lt;section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /&gt;
                  &lt;section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /&gt;&lt;/sectionGroup&gt;
          &lt;/sectionGroup&gt;
      &lt;/sectionGroup&gt;
      &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/&gt;
  &lt;/configSections&gt;
  &lt;log4net&gt;
  ...
  &lt;/log4net&gt;
  &lt;connectionStrings&gt;
      &lt;clear /&gt;
      ...
  &lt;/connectionStrings&gt;
  &lt;system.web&gt;
      &lt;pages&gt;
          &lt;controls&gt;
              &lt;add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
              &lt;add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;&lt;/controls&gt;
      &lt;/pages&gt;
      &lt;compilation debug="false"&gt;
          &lt;assemblies&gt;
              &lt;add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;
              &lt;add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
              &lt;add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;
              &lt;add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;&lt;/assemblies&gt;&lt;/compilation&gt;
      &lt;customErrors mode="RemoteOnly" /&gt;
      &lt;authentication mode="Forms"&gt;
          &lt;forms cookieless="UseCookies" loginUrl="..." name="..." path="/" protection="All" slidingExpiration="true" timeout="300" /&gt;
      &lt;/authentication&gt;
      &lt;httpHandlers&gt;
          &lt;clear /&gt;
          &lt;remove verb="*" path="*.asmx" /&gt;
          &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" /&gt;
      &lt;/httpHandlers&gt;
      &lt;httpModules&gt;
          &lt;clear /&gt;
          &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &lt;/httpModules&gt;
      &lt;machineKey validationKey="..." decryptionKey="..." validation="SHA1" /&gt;
  &lt;/system.web&gt;
  &lt;system.web.extensions&gt;
      &lt;scripting&gt;
          &lt;webServices&gt;
          &lt;/webServices&gt;
          &lt;scriptResourceHandler enableCompression="true" enableCaching="false" /&gt;
      &lt;/scripting&gt;
  &lt;/system.web.extensions&gt;
  &lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;modules&gt;
          &lt;remove name="ScriptModule" /&gt;&lt;add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &lt;/modules&gt;
      &lt;handlers&gt;
          &lt;remove name="SimpleHandlerFactory-ISAPI-2.0-64" /&gt;
          &lt;remove name="PageHandlerFactory-ISAPI-2.0-64" /&gt;
          &lt;remove name="HttpRemotingHandlerFactory-soap-ISAPI-2.0-64" /&gt;
          &lt;remove name="HttpRemotingHandlerFactory-rem-ISAPI-2.0-64" /&gt;
          &lt;remove name="xoml-ISAPI-2.0" /&gt;
          &lt;remove name="xoml-Integrated" /&gt;
          &lt;remove name="xoml-64-ISAPI-2.0" /&gt;
          &lt;remove name="WebServiceHandlerFactory-ISAPI-2.0" /&gt;
          &lt;remove name="TRACEVerbHandler" /&gt;
          &lt;remove name="SimpleHandlerFactory-ISAPI-2.0" /&gt;
          &lt;remove name="SimpleHandlerFactory-Integrated" /&gt;
          &lt;remove name="rules-ISAPI-2.0" /&gt;
          &lt;remove name="rules-Integrated" /&gt;
          &lt;remove name="rules-64-ISAPI-2.0" /&gt;
          &lt;remove name="PageHandlerFactory-ISAPI-2.0" /&gt;
          &lt;remove name="PageHandlerFactory-Integrated" /&gt;
          &lt;remove name="OPTIONSVerbHandler" /&gt;
          &lt;remove name="HttpRemotingHandlerFactory-soap-ISAPI-2.0" /&gt;
          &lt;remove name="HttpRemotingHandlerFactory-soap-Integrated" /&gt;
          &lt;remove name="HttpRemotingHandlerFactory-rem-ISAPI-2.0" /&gt;
          &lt;remove name="HttpRemotingHandlerFactory-rem-Integrated" /&gt;
          &lt;remove name="AXD-ISAPI-2.0" /&gt;
          &lt;remove name="ScriptHandlerFactory" /&gt;
          &lt;remove name="ScriptHandlerFactoryAppServices" /&gt;
          &lt;remove name="ScriptResource" /&gt;&lt;remove name="WebServiceHandlerFactory-Integrated" /&gt;
          &lt;add name="Ashx ext" path="*.ashx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" /&gt;
          &lt;add name="Aspx ext" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" /&gt;
          &lt;add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &lt;/handlers&gt;
      &lt;urlCompression doDynamicCompression="true" /&gt;
      &lt;httpRedirect enabled="false" destination="..." childOnly="false" /&gt;
      &lt;defaultDocument&gt;
          &lt;files&gt;
              &lt;remove value="Default.aspx?..." /&gt;
              &lt;remove value="default.aspx" /&gt;
          &lt;/files&gt;
      &lt;/defaultDocument&gt;
      &lt;httpErrors errorMode="Detailed" /&gt;
  &lt;/system.webServer&gt;
  &lt;appSettings&gt;
      &lt;clear /&gt;
  &lt;/appSettings&gt;
  &lt;location path="ScriptResource.axd"&gt;
      &lt;system.web&gt;
          &lt;authorization&gt;
              &lt;allow users="*" /&gt;
              &lt;deny users="?" /&gt;
          &lt;/authorization&gt;
      &lt;/system.web&gt;
  &lt;/location&gt;
  &lt;location path="WebResource.axd"&gt;
      &lt;system.web&gt;
          &lt;authorization&gt;
              &lt;allow users="*" /&gt;
              &lt;deny users="?" /&gt;
          &lt;/authorization&gt;
      &lt;/system.web&gt;
  &lt;/location&gt;
  &lt;location path="SiteMap.ashx"&gt;
      &lt;system.web&gt;
          &lt;authorization&gt;
              &lt;allow users="*" /&gt;
              &lt;deny users="?" /&gt;
          &lt;/authorization&gt;
      &lt;/system.web&gt;
  &lt;/location&gt;
  &lt;system.codedom&gt;
      &lt;compilers&gt;
          &lt;compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"&gt;
              &lt;providerOption name="CompilerVersion" value="v3.5" /&gt;
              &lt;providerOption name="WarnAsError" value="false" /&gt;&lt;/compiler&gt;
          &lt;compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"&gt;
              &lt;providerOption name="CompilerVersion" value="v3.5" /&gt;
              &lt;providerOption name="OptionInfer" value="true" /&gt;
              &lt;providerOption name="WarnAsError" value="false" /&gt;&lt;/compiler&gt;&lt;/compilers&gt;&lt;/system.codedom&gt;
  &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
          &lt;dependentAssembly&gt;
              &lt;assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" /&gt;
              &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /&gt;&lt;/dependentAssembly&gt;
          &lt;dependentAssembly&gt;
              &lt;assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" /&gt;
              &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /&gt;&lt;/dependentAssembly&gt;&lt;/assemblyBinding&gt;&lt;/runtime&gt;&lt;/configuration&gt;
  </code></pre>
  
  <p>Everything was working fine until I added this code to the main app's web.config, in order to solve a problem with json:</p>
  
  <pre><code>&lt;system.web.extensions&gt;
   &lt;scripting&gt;
    &lt;webServices&gt;
      &lt;jsonSerialization maxJsonLength="50000000"/&gt;
    &lt;/webServices&gt;
   &lt;/scripting&gt;
  &lt;/system.web.extensions&gt;
  </code></pre>
  
  <p>Then when I navigate to any page within the 2.0 app, I get the following error:</p>
  
  <p><strong>500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.</strong></p>
  
  <p>Everything works fine with the 4.0 app, the error appears only with the 2.0 app. Another interesting thing is that, after the modification, if I try to access any IIS option of the 2.0 app, the following error appears:</p>
  
  <p><strong>The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration</strong></p>
  
  <p>Any idea to solve this problem?</p>