[Development Notes]-webconfigurationmanager and configurationmanager

Source: Internet
Author: User

Writing todayProgramSome examples are occasionally discovered.CodeWebconfigurationmanager is used to obtain the configuration information in Web. config. Because the configurationmanager has been used for a long time, so I simply went into detail and made a small summary.

Msdn description:

Use Webconfigurationmanager You can access computer and application information.

use webconfigurationmanager is the preferred method for processing configuration files related to Web applications. For client applications, use configurationmanager .

 

I wonder whether it can be understood:

1. for Web applications, we recommend that you prioritize webconfigurationmanager ; however, this method is not applicable to client applications such as winform and WPF.

2. configurationmanager is applicable to web applications and client applications, but better for client applications.

 

Other sorting:

         // For client applications, use configurationmanager.          Protected   Static   String Connectionstring = configurationmanager. connectionstrings [ "  Connstr  "  ]. Tostring ();  Protected   Static   String Appconfigstring = configurationmanager. appsettings [ ""  ]. Tostring ();  // Webconfigurationmanager is the preferred method for processing configuration files related to Web applications.          Protected   Static   String Webconnectionstring = webconfigurationmanager. connectionstrings [ ""  ]. Tostring ();  Protected   Static   String Webappconfigstring = webconfigurationmanager. appsettings [ ""  ]. Tostring ();  //  Configuration nodes in Web. config: //  Connectionstrings  //  <Connectionstrings>  //  <Add name = "connstr" connectionstring = "Data Source =.; user id = sa; Pwd = 123456; database = database;"/>  //  </Connectionstrings>  //  Appsettings  //  <Deleetask>  // <Add key = "" value = ""/>  //  </Appsettings>  //  Use System. configuration. configurationmanager. deleetask[ "name"] to retrieve the value in <deleetask>.  //  In <connectionstrings>, use system. configuration. configurationmanager. connectionstrings ["name"] to retrieve the value.  //  Note:  //  System. Web. configuration does not add reference in the program by default, so direct using cannot be used. 

Appendix:

Indicate the source for reprinting.

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.