【发布时间】: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