2

在一个小型测试项目中,我目前在 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 文件。我可能在这里遗漏了一些非常简单的东西:)

希望对此有更多的投入。

谢谢五

4

1 回答 1

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" />
于 2010-05-19T20:59:42.530 回答