10

我正在尝试将程序集重定向从web.config外部文件移动。其原因是我想将绑定重定向保留在一个地方并在调试和生产配置中使用它。

它有点工作,但我正在努力指定相对路径。

<configuration>
   <!-- this works, but forces me to use the same path on dev and production machines -->
   <linkedConfiguration href="file://c:\data\web.runtime.config"/>

   <!-- none of those works -->
   <linkedConfiguration href="file://web.runtime.config"/>
   <linkedConfiguration href="file://..\web.runtime.config"/>
   <linkedConfiguration href="file://~/web.runtime.config"/>

</configuration>

我想将它保存web.runtime.config在与 Web 应用程序的其余部分相同的文件夹中。是否可以在linkedConfiguration元素中指定相对路径?

更多信息:我已经在 VS 2015 中使用 IIS Express 和 ASP MVC 应用程序对其进行了测试。当使用 SysInternals Process Monitor 监视文件访问时,相对路径似乎解析为\\web.runtime.config(无效的网络路径),而使用绝对路径时没有\\添加前导.

4

2 回答 2

3

我找到了一种指定相对路径的方法。

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <linkedConfiguration href="file:./RuntimeConfiguration.xml"/>
</assemblyBinding>
于 2018-04-04T22:20:03.490 回答
1

File web.runtime.config must be in bin dir.

And with href="file:web.runtime.config" it will be work

于 2020-01-10T10:06:48.950 回答