SectionInformation.ConfigSource 属性


获取或设置包含文件的名称,关联配置节在其中定义(如果存在这样一个文件)。Gets or sets the name of the include file in which the associated configuration section is defined, if such a file exists.

 property System::String ^ ConfigSource { System::String ^ get(); void set(System::String ^ value); };
public string ConfigSource { get; set; }
member this.ConfigSource : string with get, set
Public Property ConfigSource As String


包含文件的名称,关联的 ConfigurationSection 在其中定义(如果存在这样一个文件);否则为空字符串 ("")。The name of the include file in which the associated ConfigurationSection is defined, if such a file exists; otherwise, an empty string ("").


ConfigSource 属性表示为与 SectionInformation 对象关联的 ConfigurationSection 对象指定的 configSource 属性的值。The ConfigSource property represents the value of the configSource attribute that is specified for a ConfigurationSection object that is associated with the SectionInformation object.

ConfigurationSection 实现可以选择指定一个单独的文件,其中定义了该部分的配置设置。A ConfigurationSection implementation can optionally specify a separate file in which the configuration settings for that section are defined. 这可以通过多种方式来实现:This can be useful in multiple ways:

  • 使用包含文件可为配置文件生成更具逻辑性和模块化的结构。Using include files can result in a more logical and modular structure for configuration files.

  • 文件访问安全性和权限可用于限制对配置设置部分的访问。File-access security and permissions can be used to restrict access to sections of configuration settings.

  • 在应用程序初始化期间未使用的包含文件中的设置可以在不需要重新启动应用程序的情况下进行修改和重新加载。Settings in an include file that are not used during application initialization can be modified and reloaded without requiring an application restart.

下面的示例演示如何在配置文件中使用此属性来指定在外部包含文件中定义 pages 节:The following example shows how this attribute is used in a configuration file to specify that the pages section is defined in an external include file:

<pages configSource="pages.config"/>

如果配置包含文件中的任何设置需要在修改应用程序时重新启动该应用程序,请将 RestartOnExternalChanges 属性设置为 trueIf any of the settings in a configuration include file require the application to restart when they are modified, set the RestartOnExternalChanges property to true.

在 ASP.NET 应用程序中,可以在运行时向 ConfigSource 属性分配备用配置文件的名称。In ASP.NET applications, at run time you can assign to the ConfigSource property the name of an alternative configuration file. 在这种情况下,在 web.config 文件中包含的默认连接字符串信息将覆盖文件的内容。In that case, the contents of the file are overwritten by the default connection string information that is contained in the Web.config file. 当备用文件不存在并且在运行时创建该文件时,也会发生这种情况。This occurs also when the alternative file does not exist and it is created at run time. 如果 Web.config 文件不包含任何连接字符串信息,则会将一个空部分添加到备用文件中。If the Web.config file does not contain any connection string information, an empty section is added to the alternative file.