"Reprint" WebConfigurationManager and ConfigurationManager

Source: Internet
Author: User
Tags connectionstrings

Original link

Today, in writing the program accidentally found that some of the sample code is used WebConfigurationManager to get configuration information in Web. config, because it was always used configurationmanager, so simply dig a bit, and make a small summary.

Description of MSDN:

Use WebConfigurationManager to access computer and application information.

Using WebConfigurationManager is the preferred way to handle configuration files related to Web applications. For client applications, use ConfigurationManager.

I do not know if it can be understood as:

1. For Web applications, it is recommended that WebConfigurationManager be preferred, but this method does not apply to client applications such as WINFORM,WPF programs.

2. ConfigurationManager , which applies to Web applications, also applies to client applications, but is better for client applications.

  For client applications, use ConfigurationManager. protected static string connectionString = configurationmanager.connectionstrings["ConnStr"].        ToString (); protected static string appconfigstring = configurationmanager.appsettings[""].        ToString ();        Using WebConfigurationManager is the preferred way to handle configuration files related to Web applications. protected static string webconnectionstring = webconfigurationmanager.connectionstrings[""].        ToString (); protected static string webappconfigstring = webconfigurationmanager.appsettings[""].        ToString (); Configuration node in Web. config://connectionstrings//<connectionstrings>//<add name= "ConnStr" Connec Tionstring= "Data source=.; User Id=sa; Pwd=123456;database=database; " />//</connectionstrings>//appsettings//<appsettings>//<add key= "" Valu E= ""/>//</appsettings>//written in <appsettings > System.Configuration.ConfigurationManager.AppSet         tings["Name"] to retrieve the value. Written in &Lt        The value is retrieved in connectionstrings> with system.configuration.configurationmanager.connectionstrings["name". Note://system.web.configuration does not add references to the program by default, so the direct using cannot be used. Copy Code

  

"Reprint" WebConfigurationManager and ConfigurationManager

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.