【问题标题】:Under IIS 8.0, appcmd or inetmgr cannot make changes to web.config if <runtime>/<assemblyBinding> element is present in the file在 IIS 8.0 下,如果文件中存在 <runtime>/<assemblyBinding> 元素,appcmd 或 inetmgr 无法更改 web.config
【发布时间】:2017-07-26 10:53:33
【问题描述】:

在准备将一些应用程序移动到 IIS 8 时,我在 Windows 10 和 Windows Server 2012 R2 上遇到 hresult:c00cef03 错误,当使用 appcmd.exe 或 inetmgr 对 web.config 进行更改时,只要 web.config 文件包含 runtime/assemblyBinding 元素。

以前有人见过这种情况吗?解决方法是什么?

以下是 appcmd 输出的示例:

C:>C:\Windows\System32\inetsrv\appcmd.exe set config "Default Web Site/Configuration" -section:anonymousAuthentication /username
:""
Applied configuration changes to section "system.webServer/security/authenticati
on/anonymousAuthentication" for "MACHINE/WEBROOT/APPHOST/Default Web Site/Config
uration" at configuration commit path "MACHINE/WEBROOT/APPHOST/Default Web Site/
Configuration"
ERROR ( hresult:c00cef03, message:Failed to commit configuration changes.
 )

以下是您可以用来重现问题的 web.config 文件的内容。似乎只有元素的存在就会导致错误发生,程序集的身份无关紧要。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <authentication>
        <anonymousAuthentication enabled="true" userName="IUSR" />
      </authentication>
    </security>
  </system.webServer>
  <runtime>
    <asm:assemblyBinding xmlns:asm="urn:schemas-microsoft-com:asm.v1">
      <asm:dependentAssembly>
        <asm:assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <asm:bindingRedirect oldVersion="4.5.0.0-9.0.0.0" newVersion="9.0.0.0" />
      </asm:dependentAssembly>
    </asm:assemblyBinding>
  </runtime>
</configuration>

【问题讨论】:

  • Windows 10 运行 IIS 10。
  • 我可以重现此问题,但找不到简单的解决方法。在这种情况下,即使是 IIS Manager 也无法进行更改,因此应该是 MWA 的错误。
  • 我认为原因是 &lt;runtime&gt; 标签及其子标签在 IIS 中没有注册响应架构信息。是否可以通过添加架构文件来解决此问题。
  • 我在 2012R2 架构中找不到 标记,在 2008R2 架构中也找不到;但是2008R2没有这样的问题。原因可能是别的。

标签: iis-8


【解决方案1】:

这不是一个真正的答案。

我无权访问 Microsoft 源代码,但维护 an IIS Manager clone。因此,在阅读了您的描述后,我继续进行了调查。到目前为止,我的结论是 &lt;runtime&gt; 标记不能通过模式文件轻松处理。 (这就是为什么没有现有的架构文件来处理它,这与 &lt;system.web&gt; 项目不同,后者有自己的架构文件)。

我给 Jexus Manager 的解决方案是 a new commit,通过读取 machine.config&lt;runtime&gt; 标记将被忽略。

我只能猜测 IIS 7.0 和 7.5 中的 IIS 管理器也使用相同的技巧来忽略 &lt;runtime&gt; 标记。但是开发人员可能已经为 .NET Framework 2.0 硬编码了System.Configuration.IgnoreSection,它不适用于 .NET Framework 4.0 及更高版本,并且可能导致您遇到的问题。一个支持事实是,对于 IIS 8.0 及更高版本,IIS 管理器(和 MWA API)完全在 .NET Framework 4.0 上运行,不再是 2.0。

嗯,在这个阶段你只能将这个错误报告给微软,希望他们能修复它。如果他们不想修复,你几乎别无选择,只能使用变通方法,比如

  • 在调用 IIS API 之前删除 &lt;runtime&gt; 标记,并在完成后将其重新添加。

很遗憾,我没有足够的时间来开发基于 Jexus Manager 代码库的 appcmd 克隆。否则,您可以尝试一下。

【讨论】:

  • 谢谢莱克斯!我将向 Microsoft 开一张支持票。
【解决方案2】:

Microsoft 的建议是从程序集绑定元素中删除 XML 命名空间前缀,我已经验证它已经解决了问题。虽然拒绝正确的 XML 语法并不理想,但这是一个可以接受的解决方案。

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="4.5.0.0-9.0.0.0" newVersion="9.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 2014-03-29
    • 1970-01-01
    • 2021-06-28
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多