The key class in the System.Configuration namespace

Original link: http://www.cnblogs.com/ycat/archive/2006/08/19/481083.html

1.ConfigurationManager and WebConfigurationManager categories:
 
    use ConfigurationManager class, you can access the computer's configuration information and applications. ConfigurationManager is the preferred method for handling client application configuration files; do not recommend using any other method. For Web applications, it is recommended to use WebConfigurationManager class.
The client application running on the client computer, and run the Web application client connects to the server computer.
Use the built-System.Configuration types or derived from them to process configuration information. By using these types, the configuration information can be directly processed, the configuration file and can be extended to include the custom information.

ConfigurationManager class includes members used to perform the following tasks.

      read a section from the configuration file. To access the configuration information, use GetSection. For some of these, like appSettings section and connectionStrings, please use the AppSettings and ConnectionStrings class. The method of the above-mentioned read-only operations, a single cache instance configuration, and may identify the multiple threads.

      configuration file as a whole reads and writes. Applications can read and write configuration settings at any level, whether it is their own or other applications or computers, but also whether it is local or remote. One method uses an openable ConfigurationManager class provides similar Myapp.exe.config this profile. These methods return a Configuration object, which in turn can be used in the disclosed methods and properties associated with the profiles of the process. The method of performing a read or write operation, and each time a file is written to recreate the configuration data.

      support configuration tasks. The following types are used to support various configuration tasks:

SectionInformation
PropertyInformation
PropertyInformationCollection
ElementInformation
ContextInformation
ConfigurationSectionGroup
ConfigurationSectionGroupCollection

In addition to the conventional processing configuration information, but also can be created and processed by custom configuration elements extend the built type of configuration (e.g. ConfigurationElement, ConfigurationElementCollection, ConfigurationProperty ConfigurationSection and the like). For information about how to programmatically extended example of the type of built-in configuration, see ConfigurationSection. Examples of how to use built-in configuration based on the type of model extended attributes, see ConfigurationElement.

Configuration class allows programmatic access to edit the configuration file. Open uses a method of ConfigurationManager provided. These methods return a Configuration object, which in turn provides processing methods and properties required of the base profile. You can access these files for reading or writing. To read the configuration file, use GetSection or GetSectionGroup read configuration information. Read user or process must have the following rights: If the application requires read-only access to its own configuration, GetSection recommended method. This method provides access to the current value of the cache configuration of the application, its performance is better than the Configuration class.

2.Configuration categories:

Merge View Configuration class instance configuration settings represented by these configuration settings for a particular physical entity (such as a computer) or a logical entity (e.g., application or website). Specified logical entities can exist on the local computer or a remote server. When a profile is not specified entity, the default configuration settings Configuration object represents Machine.config document definition. By using one of the methods defined for that class Open configuration you can obtain the Configuration object. Use one of the Save method, you can save the configuration information Coonfiguration object to a disk file

3. ConfigurationSection class

    can use ConfigurationSection implement a custom section type. ConfigurationSection extended class to provide custom processing and access to the programming section of the custom configuration. All of the default configuration section ConfigurationSection by extension classes to represent the class.

ConfigSections use items registered in their type of processing.

      3.1 ConfigurationSection实现说明:
      可以使用编程或声明性(属性化)代码编写模型创建自定义配置节。

              3.1.1 编程模型。此模型要求为每个节属性 (Attribute) 创建一个用于获取和/或设置其值的属性 (Property),并将其添加 到基础 ConfigurationElement 基类的内部属性 (Property) 包中。

              3.1.2 声明性模型。这种比较简单的模型也称为属性 (Attribute) 化模型,允许您通过使用属性 (Property) 来定义节属性 (Attribute),并使用属性 (Attribute) 对其进行修饰。这些属性 (Attribute) 将属性 (Property) 类型及其默认值通知给配置系统。配置系统将使用通过反射获取的这些信息为您创建节属性 (Property) 对象并执行所需的初始化。

   3.2 Configuration 是允许进行编程访问以编辑配置文件的类。您可以按照以下说明访问这些文件以进行读写操作。
             3.2.1 读取。使用 GetSection 或 GetSectionGroup 读取配置信息。请注意,进行读取操作的用户或进程必须具有以下权限:
      在当前配置层次结构级别下对配置文件的读取权限。
      对所有父级配置文件进行读取的权限。

      如果应用程序需要对其自己的配置进行只读访问,建议对于 Web 应用程序使用 GetSection 重载方法。或使用 GetSection 方法(针对客户端应用程序)。 这些方法可提供对当前应用程序的缓存配置值的访问,且其性能要好于 Configuration 类。
      如果使用带有路径参数的静态 GetSection 方法,则该路径参数必须引用代码正在运行的应用程序,否则,该参数将被忽略,并返回当前正在运行的应用程序的配置信息。
             3.2.2 写入。可使用 Save 方法之一写入配置信息。请注意,进行写入操作的用户或进程必须具有以下权限:
      对当前配置层次结构级别的配置文件和目录的写入权限。
      对所有配置文件的读取权限。

转载于:https://www.cnblogs.com/ycat/archive/2006/08/19/481083.html

Guess you like

Origin blog.csdn.net/weixin_30312659/article/details/94798925