Configuration files are used in many cases, and the configuration file is divided into two types: the application configuration file and the Web configuration file.
The biggest difference between the two profiles is that the Web's profile updates are updated in real time and the application's configuration files are not updated in real time.
Refresh the application's configuration file after you update it
Configurationmanager.refreshsection ("appSettings");//refreshes the named section and re-reads it from disk the next time it is retrieved.
ConfigurationSettings also has this problem, but I don't know how to refresh the node,
< Configuration > < appSettings > < key= "name" value= "I am a remote server"/> </ appSettings></configuration > Background program is worth reading: string s=system.configuration.configurationsettings.appsettings["name"];
system.configuration.configurationsettings.appsettings["Key"];
But now FrameWork2.0 has made it clear that this property is obsolete. It is recommended to change to ConfigurationManager or WebConfigurationManager. And the AppSettings property is read-only and does not support modifying property values.
However, to invoke ConfigurationManager, you must first add a reference to the System.Configuration.dll assembly in the project. (Right-click the project name in the Solution Manager, select Add Reference in the right-click menu, find it under. NET Tablepage) Add reference can be used with String str = configurationmanager.appsettings["Key"] To get the corresponding value.
To update a configuration file:
Configuration CFA = configurationmanager.openexeconfiguration (Configurationuserlevel.none);
Add to
CfA. APPSETTINGS.SETTINGS.ADD ("Key", "Name")
Modify
CfA. appsettings.settings["Browsedir"]. Value = "name";
Last Call
CfA. Save ();
The current configuration file update was successful.
Configurationmanager.refreshsection ("appSettings");//refreshes the named section and re-reads it from disk the next time it is retrieved. Remember that the application will refresh the node
Connection string notation:
< connectionStrings > < name= "DefaultConnection" connectionString= "Data source=.\sqlexpress; attachdbfilename=| Datadirectory|\aspnet-mvcweb-20150702180004.mdf;initial catalog=aspnet-mvcweb-20150702180004;integrated Security =true; User instance=true " providerName=" System.Data.SqlClient "/> </connectionStrings>
[Go]c# configuration file