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.