. Net application configuration and basic configuration methods (1)
I. How should I configure an application?
1. Create an XML file as the configuration file, define the required node or node tree, and store the parameter values in the node attributes or text.
2. Create a class, for example, ForumConfig. The attributes of this class are mapped to the names and attributes of a configuration node in XML to provide strong type access.
3. Create a configuration file lifecycle class, such as ConfigManager. add a method, such as GetSection (string nodeName), and then use System. the method in the Xml namespace obtains the node attribute value or text value. Finally, assign values to the attributes of the ForumConfig instance, and then return the instance.
4. Access the configured node value through an instance similar to ForumConfig in the program.
2. Structure of the application configuration file in. net:
The configuration file is divided into two parts: the actual configuration content;
The other part specifies the node handler.
(In general, it is the class information of configuration information + operation configuration information)
The built-in node settings are all located:
C: WindowsMicrosoft. NETFramework4.0.30319Config
To provide global services. (Slightly different)
3. Two types of handlers in machine. config
4. Demo
When the configuration file was first used to load the assembly, the built-in. net handler was defined in machine. config to provide global services, which can be directly used without additional work.
Read configuration information in the program: