【问题标题】:web.config assembly redirect linked configurationweb.config 程序集重定向链接配置
【发布时间】:2023-01-11 05:49:44
【问题描述】:

我有一个 IIS 服务器应用程序,我想在另一个文件中设置绑定重定向,该文件可供我整个系统的其他部分使用。

为此,我已经阅读了有关 linkedConfiguration-Element 的信息。

所以在 web.config 中我有以下重定向:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-5.2.9.0" newVersion="5.2.9.0"/>
  </dependentAssembly>
</assemblyBinding>

我将其替换为以下内容:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <linkedConfiguration href="file://D:\Dev\IIS\AssemblyBindingRedirects.xml"/>
</assemblyBinding>

AssemblyBindingRedirects.xml 的内容是:

  <runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-5.2.9.0" newVersion="5.2.9.0"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

不幸的是,这似乎不起作用。我收到一个错误,在运行时检测到错误版本的 Newtonsoft.Json。我已经检查过 AssemblyBindingRedirects.xml 是否存在于正确的目录中并且在运行时存在。

我究竟做错了什么?

【问题讨论】:

  • 您是否在 xml 中添加了 <?xml version="1.0"?> <configuration>?
  • 那不是问题所在。问题是我在运行时元素下的 web.Config 中有 linkedConfiguration。这一定在这之外。我遇到的另一个问题是你不能在 web.config 中使用相对路径

标签: c# iis web-config


【解决方案1】:

web.config 中,linkedConfiguration-Element 是runtime-Element 的子元素。那就是问题所在。如果我将它移到 runtime-Element 之外,它就可以工作。

但前提是我在 href-Attribute 中使用完全限定路径。如果我尝试使用相对路径,它不起作用,因为 web.config 中不允许使用相对路径

【讨论】:

    猜你喜欢
    • 2014-08-02
    • 1970-01-01
    • 2017-01-03
    • 2011-11-13
    • 2019-03-25
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    相关资源
    最近更新 更多