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