. Net application configuration and basic configuration methods (1)

Source: Internet
Author: User

. 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:

 

 

 

 

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.