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

标签 c# .net 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>

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

<runtime configSource="Redirects.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"]

关于c# - 为 bindingRedirects 定义单独的 configSource 并在 app.config 中引用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23559270/

相关文章:

c# - 目标框架中缺少“WindowsBase”、 'PresentationCore'、 'PresentationFramework'

c# - Entity Framework 错误 : An object with a null EntityKey value cannot be attached to an object context

c# - 是否为每个新实例实例化基类?

c# - 如何从富文本框向word文档中插入文本

python - 如何将应用程序设置保存在配置文件中?

c# - 基于 app.config 值的不同 app.config appSettings

c# - 如何从 Visual studio 2017 预览版 2 指定 Azure Function 的输出绑定(bind)?

c# - 为什么 Visual C# express 2010 变得缓慢且不稳定,任务管理器中的句柄变得过高?

c# - 如果事件在 .NET 中作为委托(delegate)实现,那么 .event IL 部分的意义何在?

c# - ConfigurationManager.AppSettings - 返回 Null