为提供者分离配置文件

时间:2010-05-19 20:53:31

标签: config provider

在一个小型测试项目中,我目前在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

1 个答案:

答案 0 :(得分:0)

如果要在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" />
相关问题