错误500和“配置部分'system.web.extensions'无法读取,因为它缺少部分声明”

时间:2016-07-01 09:59:09

标签: c# asp.net .net iis

我在带有.NET Framework 4.0(IIS 7.5)的Windows Server 2008 R2 Datacenter上安装了.NET Web应用程序。我有一个主4.0应用程序和一个嵌套的2.0应用程序。我为每个应用程序配置了IIS。 2.0文件夹已转换为应用程序,并在2.0应用程序池中运行。 4.0应用程序是根应用程序,它设置为在4.0应用程序池中运行。

这是主4.0应用程序的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<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" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
</configSections>
<exceptionHandling>
<exceptionPolicies>
  <add name="LibraryPolicy">
    <exceptionTypes>
      <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow" />
    </exceptionTypes>
  </add>
</exceptionPolicies>
</exceptionHandling>
<log4net>
...
</log4net>
<connectionStrings>
...
</connectionStrings>
<appSettings>
...
</appSettings>
<location inheritInChildApplications="false">
    <system.web>
        <httpRuntime executionTimeout="300" maxRequestLength="51200" requestValidationMode="2.0" />
        <authorization>
            <deny users="?" />              
        </authorization>            
        <compilation debug="false" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Web.Mobile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
            </assemblies>
        </compilation>

        <customErrors mode="RemoteOnly" />

        <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">
            <providers>
                <clear />
            </providers>
        </sessionState>

        <authentication mode="Forms">
            <forms loginUrl="public/default.aspx" name=".ABABABA" timeout="3000" />
        </authentication>

        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />

    </system.web>
</location>
<location path="app20" allowOverride="false">
    <system.web>
        <trust level="High" />
    </system.web>
  </location>
<location path="ScriptResource.axd">
    <system.web>
        <authorization>
            <allow users="*" />
            <deny users="?" />
        </authorization>
    </system.web>
</location>
<location path="WebResource.axd">
    <system.web>
        <authorization>
            <allow users="*" />
            <deny users="?" />
        </authorization>
    </system.web>
</location>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <remove name="WebServiceHandlerFactory-Integrated" />
        <remove name="ScriptHandlerFactory" />
        <remove name="ScriptHandlerFactoryAppServices" />
        <remove name="ScriptResource" />
        <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" />
        <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" />
        <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" />
    </handlers>
    <urlCompression doDynamicCompression="true" />
    <tracing>
        <traceFailedRequests>
            <add path="*">
                <traceAreas>
                    <add provider="WWW Server" areas="Rewrite" verbosity="Verbose" />
                </traceAreas>
                <failureDefinitions statusCodes="200-399" />
            </add>
        </traceFailedRequests>
    </tracing>
    <defaultDocument enabled="true">
        <files>
            <clear />
            <add value="Default.aspx" />
            <add value="Index.html" />
            <add value="Index.htm" />
            <add value="Index.cfm" />
            <add value="Index.shtml" />
            <add value="Index.shtm" />
            <add value="Index.stm" />
            <add value="Index.php" />
            <add value="Index.php3" />
            <add value="Index.asp" />
            <add value="Index.aspx" />
            <add value="Default.htm" />
            <add value="Default.asp" />
        </files>
    </defaultDocument>
    <httpProtocol>
        <customHeaders>
            <remove name="X-Powered-By" />
            <add name="X-UA-Compatible" value="IE=Edge,chrome=1" />
        </customHeaders>
    </httpProtocol>
    <httpRedirect enabled="false" />
    <rewrite>
        <rules>
            <rule name="CanonicalHostNameRule1">
                ...
            </rule>
        </rules>
    </rewrite>
</system.webServer>
<system.serviceModel>
    <bindings>
        ...
    </bindings>        
    <client>
        ...
    </client>
</system.serviceModel>
<system.web>
    <globalization culture="es-ES" uiCulture="es-ES" />
    <machineKey decryptionKey="..." validationKey="..." />
</system.web>
</configuration>

这是嵌套2.0应用程序的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
    <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, Version=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>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
...
</log4net>
<connectionStrings>
    <clear />
    ...
</connectionStrings>
<system.web>
    <pages>
        <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /></controls>
    </pages>
    <compilation debug="false">
        <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /></assemblies></compilation>
    <customErrors mode="RemoteOnly" />
    <authentication mode="Forms">
        <forms cookieless="UseCookies" loginUrl="..." name="..." path="/" protection="All" slidingExpiration="true" timeout="300" />
    </authentication>
    <httpHandlers>
        <clear />
        <remove verb="*" path="*.asmx" />
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <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" />
        <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" />
    </httpHandlers>
    <httpModules>
        <clear />
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </httpModules>
    <machineKey validationKey="..." decryptionKey="..." validation="SHA1" />
</system.web>
<system.web.extensions>
    <scripting>
        <webServices>
        </webServices>
        <scriptResourceHandler enableCompression="true" enableCaching="false" />
    </scripting>
</system.web.extensions>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
        <remove name="ScriptModule" /><add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </modules>
    <handlers>
        <remove name="SimpleHandlerFactory-ISAPI-2.0-64" />
        <remove name="PageHandlerFactory-ISAPI-2.0-64" />
        <remove name="HttpRemotingHandlerFactory-soap-ISAPI-2.0-64" />
        <remove name="HttpRemotingHandlerFactory-rem-ISAPI-2.0-64" />
        <remove name="xoml-ISAPI-2.0" />
        <remove name="xoml-Integrated" />
        <remove name="xoml-64-ISAPI-2.0" />
        <remove name="WebServiceHandlerFactory-ISAPI-2.0" />
        <remove name="TRACEVerbHandler" />
        <remove name="SimpleHandlerFactory-ISAPI-2.0" />
        <remove name="SimpleHandlerFactory-Integrated" />
        <remove name="rules-ISAPI-2.0" />
        <remove name="rules-Integrated" />
        <remove name="rules-64-ISAPI-2.0" />
        <remove name="PageHandlerFactory-ISAPI-2.0" />
        <remove name="PageHandlerFactory-Integrated" />
        <remove name="OPTIONSVerbHandler" />
        <remove name="HttpRemotingHandlerFactory-soap-ISAPI-2.0" />
        <remove name="HttpRemotingHandlerFactory-soap-Integrated" />
        <remove name="HttpRemotingHandlerFactory-rem-ISAPI-2.0" />
        <remove name="HttpRemotingHandlerFactory-rem-Integrated" />
        <remove name="AXD-ISAPI-2.0" />
        <remove name="ScriptHandlerFactory" />
        <remove name="ScriptHandlerFactoryAppServices" />
        <remove name="ScriptResource" /><remove name="WebServiceHandlerFactory-Integrated" />
        <add name="Ashx ext" path="*.ashx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
        <add name="Aspx ext" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
        <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" />
        <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" />
        <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" />
    </handlers>
    <urlCompression doDynamicCompression="true" />
    <httpRedirect enabled="false" destination="..." childOnly="false" />
    <defaultDocument>
        <files>
            <remove value="Default.aspx?..." />
            <remove value="default.aspx" />
        </files>
    </defaultDocument>
    <httpErrors errorMode="Detailed" />
</system.webServer>
<appSettings>
    <clear />
</appSettings>
<location path="ScriptResource.axd">
    <system.web>
        <authorization>
            <allow users="*" />
            <deny users="?" />
        </authorization>
    </system.web>
</location>
<location path="WebResource.axd">
    <system.web>
        <authorization>
            <allow users="*" />
            <deny users="?" />
        </authorization>
    </system.web>
</location>
<location path="SiteMap.ashx">
    <system.web>
        <authorization>
            <allow users="*" />
            <deny users="?" />
        </authorization>
    </system.web>
</location>
<system.codedom>
    <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
            <providerOption name="CompilerVersion" value="v3.5" />
            <providerOption name="WarnAsError" value="false" /></compiler>
        <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
            <providerOption name="CompilerVersion" value="v3.5" />
            <providerOption name="OptionInfer" value="true" />
            <providerOption name="WarnAsError" value="false" /></compiler></compilers></system.codedom>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /></dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /></dependentAssembly></assemblyBinding></runtime></configuration>

一切正常,直到我将此代码添加到主应用程序的web.config中,以解决json的问题:

<system.web.extensions>
 <scripting>
  <webServices>
    <jsonSerialization maxJsonLength="50000000"/>
  </webServices>
 </scripting>
</system.web.extensions>

然后当我导航到2.0应用程序中的任何页面时,我收到以下错误:

500 - 内部服务器错误。您正在查找的资源存在问题,无法显示。

使用4.0应用程序一切正常,只有2.0应用程序才会出现错误。另一个有趣的事情是,在修改之后,如果我尝试访问2.0应用程序的任何IIS选项,则会出现以下错误:

无法读取配置部分'system.web.extensions',因为它缺少部分声明

有什么想法解决这个问题?

1 个答案:

答案 0 :(得分:1)

在web.config中尝试此操作

<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
            <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
        </sectionGroup>
    </sectionGroup>
</sectionGroup>