为 bindingRedirects 定义单独的 configSource 并在 app.config 中引用它

Fab*_*ann 5 .net c# app-config configsource

我正在尝试定义一个单独的配置文件(比如redirect.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>
Run Code Online (Sandbox Code Playgroud)

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

<runtime configSource="Redirects.config" />
Run Code Online (Sandbox Code Playgroud)

不幸的是,它根本不起作用。复制到输出目录设置为“始终复制”。有任何想法吗?提前致谢

azh*_*dge -4

这样做将此添加到您的 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>
Run Code Online (Sandbox Code Playgroud)

现在在您的 C# 代码中调用它

string url=ConfigurationManager.AppSettings["redirectToHome"]
Run Code Online (Sandbox Code Playgroud)