【问题标题】:Separate config file for Providers提供者的单独配置文件
【发布时间】:2010-05-19 20:53:31
【问题描述】:

在一个小型测试项目中,我目前在 web.config 中有提供程序部分。我想把它移到一个单独的配置文件中,比如 providers.config。我当前的提供者实例化代码如下:

   //Get the feature's configuration info
                    ProviderConfiguration pc = (ProviderConfiguration)ConfigurationManager.GetSection(DATA_PROVIDER_NAME);

如果提供程序信息在 web.config 中,则此代码有效,但是如何从另一个文件(如 providers.condfig)中读取此信息,因为似乎 ConfigurationManager “读取”仅 web.config 文件。我可能在这里遗漏了一些非常简单的东西:)

希望对此有更多意见。

谢谢 V

【问题讨论】:

  • 我已经用我自己的配置部分测试了编辑,它工作正常。

标签: config provider


【解决方案1】:

如果您想为 web.config 中的一组设置引用外部文件,您可以这样做:

<?xml version="1.0"?>
<configuration>

<appSettings file="externalSettings.config"/>

<connectionStrings/>

<system.web>

    <compilation debug="false" strict="false" explicit="true" />

</system.web>

希望这会有所帮助。

所以在你的情况下,你可以这样做:

 <configSections>
    <section name="ProviderName" type="System.Configuration.NameValueSectionHandler" />
  </configSections>
  <ProviderName file="provider.config" />

【讨论】:

  • 感谢 Richard,我知道文件或 configsource 属性:)。但是这里的问题是提供程序部分,例如:
  • 理查德,我想我没有把我的问题说清楚,为此道歉。实际上,如果我使用文件名,那么我将不得不为每个提供商都这样做,这是我正在考虑摆脱的事情。基本上我什至不想在 web.config 中提及任何提供程序部分(甚至不是
    的东西)。我想要另一个配置类中的所有信息
猜你喜欢
  • 2011-03-05
  • 2013-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多