为绑定重定向定义单独的configSource,并在app.config中引用它

本文关键字:app 并在 config 引用 configSource 重定向 绑定 定义 单独 | 更新日期: 2023-09-27 18:02:42

我试图定义一个单独的配置文件(让我们说重定向.config)。这个单独的配置文件包含如下的assemblyBindings:

<?xml version="1.0" encoding="utf-8" ?>
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="NServiceBus.Core" publicKeyToken="9fc386479f8a226c" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

在app.config中我想引用这个redirect.config:

<runtime configSource="Redirects.config" />

不幸的是,它根本不起作用。Copy to Output Directory设置为Copy always。什么好主意吗?提前感谢

为绑定重定向定义单独的configSource,并在app.config中引用它

这样做,将此添加到您的web.config

<configuration>
<configSections>
<section name="redirect" type="CustomType"/>
<redirect>
<settings>
<add name="redirectToHome" value="https://abc.com/Home"/>
</setting>
 //You may add account node in this section or any other node you want to relate.
</redirect>
</configSections>
</configuration>

现在在你的c#代码中通过

调用它
string url=ConfigurationManager.AppSettings["redirectToHome"]
相关文章: