找到你要的答案

Q:defining separate configSource for bindingRedirects and reference it in app.config

Q:定义在app.config bindingredirects参考将configSource

i'm trying to define a separate configuration file (lets say redirect.config). This separate config file contains assemblyBindings as follow:

<?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>

In the app.config I want to reference this redirect.config:

<runtime configSource="Redirects.config" />

Unfortunately it is not working at all. Copy to Output Directory is set to "copy always". Any ideas? Thanks in advance

我试图定义一个单独的配置文件(让我们说重定向)。这个单独的配置文件中包含的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" />

不幸的是,它不是在所有工作。复制到输出目录设置为“总是复制”。有什么想法?先谢谢了。

answer1: 回答1:

Do this way add this to you 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>

Now in your C# code call it by

string url=ConfigurationManager.AppSettings["redirectToHome"]

这样做的方式添加到你的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#  .net  app-config  configsource