C # How to get the content of the web. config configuration file
This example describes how to obtain the content of the web. config configuration file in C. Share it with you for your reference. The specific implementation method is as follows:
1. ConfigurationManager provides access to the client application configuration file.
ConnectionStrings has two attributes: ConnectionStrings, which obtains the ConnectionStringsSection data configured by default in the current application.
Method 1:
The Code is as follows:
String myConn = System. Configuration. ConfigurationManager. ConnectionStrings ["sqlConnectionString"]. ConnectionString;
Method 2:
The Code is as follows:
String connString = System. Web. Configuration. WebConfigurationManager. ConnectionStrings ["sqlConnectionString"]. ToString ();
The configuration in web. config is as follows:
The Code is as follows:
<Configuration>
<ConnectionStrings>
<Add name = "sqlConnectionString" connectionString = "LocalSqlServer: data source = 127.0.0.1; Integrated Security = SSPI; Initial Catalog = aspnetdb"
ProviderName = "System. Data. SqlClient"/>
</ConnectionStrings>
</Configuration>
2. AppSettings get the AppSettingsSection data configured by default in the current application.
The Code is as follows:
String myConn = ConfigurationManager. etettings ["sqlConnectionString"]. ToString ();
The configuration in web. config is as follows:
The Code is as follows:
<Configuration>
<Deleetask>
<Add key = "sqlConnectionString" value = "Monday, January 23,200 6 2:56:14"/>
</AppSettings>
</Configuration>
I hope this article will help you with C # programming.