首页 > 代码库 > [C#常用代码]类库中读取解决方案web.Config字符串

[C#常用代码]类库中读取解决方案web.Config字符串

对于类库里读取解决方案web.config文件里字符串的方法
一.读取键值对的方法;
1.添加引用
using System.Configuration;
2.web.Config配置节
<appSettings>
    <!--现场维护从当前月向前跨几个月-->
    <add key="CrossMonthNum" value="http://www.mamicode.com/2"/>
  </appSettings>
3.代码
 public static string FileUploadPath
{
    get
    {
        //return System.Web.Configuration.WebConfigurationManager.AppSettings["fileStorePath"];
        return ConfigurationManager.AppSettings["fileStorePath"];
    }
}


二.读取数据库连接串
1.添加引用
using System.Configuration;
2.web.Config配置节
 
  <connectionStrings>
    <!--Oracel链接-->
    <add name="ERP_FT800" connectionString="metadata=res://*/ERP.csdl|res://*/ERP.ssdl|res://*/ERP.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;DATA SOURCE=FT8000;PASSWORD=fterp201501!!;PERSIST SECURITY INFO=True;USER ID=ft800&quot;" 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;Password=P@ssw0rd" 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数据库接口-->
    <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"/>
    <!--临时使用  模拟特采系统或其他SQLServer数据库接口-->               
    <add name="FTCE_Interface_SystemCon" connectionString="Data Source=192.168.130.111;Initial Catalog=FTCE_Interface;Persist Security Info=True;User ID=sa;Password=P@ssw0rd" providerName="System.Data.SqlClient"/>
  </connectionStrings>
3.读取字符串代码
ConfigurationManager.ConnectionStrings["FTCE_CW_SystemCon"].ConnectionString

[C#常用代码]类库中读取解决方案web.Config字符串