This time we discuss reading the settings values that focus primarily on the following Web. config configuration file.
1, <connectionstring/> The connection string read.
2, <appsettings/> Application Set the value of the read.
3, <mailsettings/>SMTP Mail Set the value of reading.
In the discussion read the above 3 node configuration Money Let's talk about the following 3 classes:
1, Configuration Class (System.Configuration.Configuration).
2, WebConfigurationManager Class (System.Web.Configuration.WebConfigurationManager).
3, ConfigurationManager Class (System.Configuration.ConfigurationManager).
The following is a general introduction to the features of these 3 classes.
1. Configuration class:
You can treat a configuration class as a config ontology for a. NET application, including Web or Windows-based applications, through which you visit the Web. config file of an ASP. Web site or the app. Config file for a Windows Form project. But the configuration class must be paired with the WebConfigurationManager or ConfigurationManager class, to see if the application is an ASP. NET or Windows Form type. NET uses the WebConfigurationManager class, Windows form uses the ConfigurationManager class.
2, WebConfigurationManager class:
The WebConfigurationManager class is to provide access to the Web. config, for example, to open a part of Web. config (section) in the WebConfigurationManager class and return it to the configuration class for processing.
3, ConfigurationManager Class
The ConfigurationManager class provides access to app. Config, for example, by opening a section of app. Config in the ConfigurationManager class and then returning to the configuration class for processing.
Summary: The final collocation of the use of the way.
1), ASP. NET Web page: Configuration Class +webconfigurationmanager class.
2), Windows Forms Type: Configuration Class +configurationmanager class.
Note:
A, although WebConfigurationManager and ConfigurationManager class functions are interoperability, but Microsoft construction is clearly differentiated use.
B, WebConfigurationManager and ConfigurationManager all belong to static class, can be taken directly, do not need new a instance instance.