代码之家  ›  专栏  ›  技术社区  ›  Vivek

提供程序的单独配置文件

  •  2
  • Vivek  · 技术社区  · 14 年前

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

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

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

    希望得到更多的信息。

    谢谢 V

    1 回复  |  直到 14 年前
        1
  •  0
  •   Richard    14 年前

    如果要引用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" />