Methods for reading strings in the solution Web. config file for a class library
I. Methods of reading key-value pairs;
1. Adding references
Using System.Configuration;
2.web. Config configuration section
<appSettings>
<!--onsite maintenance from the current month forward a few months--
<add key= "Crossmonthnum" value= "2"/>
</appSettings>
3. Code
public static string Fileuploadpath
{
Get
{
return system.web.configuration.webconfigurationmanager.appsettings["Filestorepath"];
return configurationmanager.appsettings["Filestorepath"];
}
}
Two. Read the database connection string
1. Adding references
Using System.Configuration;
2.web. Config configuration section
<connectionStrings>
<!--oracel Link--
<add name= "erp_ft800" connectionstring= "metadata=res://*/erp.csdl|res://*/erp.ssdl|res://*/erp.msl;provider= Oracle.manageddataaccess.client;provider connection String="data source=ft8000; password=fterp201501!!; PERSIST SECURITY info=true; USER id=ft800" "providername=" System.Data.EntityClient "/>
<add name= "Ftce_accs_systemcon" connectionstring= "Data source=192.168.10.611;initial Catalog=FTCE_ACCS; Persist Security info=true; User Id=sa; [Email protected] "providername=" System.Data.SqlClient "/>
<add name= "ftceoracle" connectionstring= "Data Source=ftcesys; Persist Security info=true; User Id=lqmuser; Password=qmuser "providername=" System.Data.OracleClient "/>
<!--ERP Database interface---
<add name= "erporacle" connectionstring= "Data source=fterp; Persist Security info=true; User id=ft800; password=fterp201501!! "providername=" System.Data.OracleClient "/>
<add name= "erp_readonly" connectionstring= "Data source=fterp; Persist Security info=true; User id=ft800; password=fterp201501!! "providername=" System.Data.OracleClient "/>
<!--temporary use of a mock-up system or other SQL Server database interface--
<add name= "Ftce_interface_systemcon" connectionstring= "Data source=192.168.130.111;initial Catalog=FTCE_ Interface; Persist Security info=true; User Id=sa; [Email protected] "providername=" System.Data.SqlClient "/>
</connectionStrings>
3. Reading the string code
configurationmanager.connectionstrings["Ftce_cw_systemcon"]. ConnectionString
Read the solution web in the [C # Common Code] class library. Config string