IIS 7 throws "duplicate section defined" error for web.config on one server, but not another
I have 3 servers, all of which are running Windows Web Server, .NET 4, and IIS7. The beginning section of my web.config file is:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Vers开发者_开发知识库ion=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
This works fine on 2 of the servers, but one of them reports the error:
There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
against the line:
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
If I remove that single line, then it complains about a duplicate of the next line, and so on until I remove almost all of the config sections.
Any idea what would cause this?
Edit:
This was a .NET 3.5 application that was updated to VS 2010 and .NET 4. All 3 servers have .NET 2/3.5 and 4 installed. The IIS app pools have all been updated to .NET 4.
In all 3 servers, the machine.config
file already has some of these web.config sections defined in it (as Damien's answer mentions), but only 1 of the 3 complains about it being duplicated.
On the "broken" server your app pool is running .NET 4.0. The fix is to set the app pool to run as .NET 2.0.
Because ASP.NET AJAX was invented after .NET 2.0, the configuration definitions never made it into the central web.config so you had to declare them on a per-site basis in most circumstances. 4.0 cleaned up lots of that cruft, with the side effect of breaking the default configurations for preceding versions of ASP.NET.
Having checked the machine.config
on my machine, it seems to have these sections defined already. Have they been removed from the other machines' machine.config
(Or was the site, in fact, running under an earlier version of ASP.Net on these other servers?)
So far as I can see, these sections are defined by a default install of ASP.NET 4 within machine.config
.
I was getting a similar error about duplicated sections and fixed it deploying to a different website on IIS.
I had tons of old applications deployed on that website and I think there were some conflict with the web.config.
I just deleted the website, create a new one and deploy there and it worked.
精彩评论