using System.Configuration;//导入命名空间
//配置文件 Web.config
<appSettings>
<!--数据连接字符串-->
<add key="SqlConnectionStr" value="server=.;uid=sa;pwd=sa;database=RCCMS"/>
</appSettings>
//在程序里获得配置文件的Key对应的值
System.Configuration.ConfigurationSettings.AppSettings["SqlConnectionStr"];
转载于:https://www.cnblogs.com/chenze-Index/p/10277852.html