C# 从配置文件中读取/写入信息

读取:

 var currMemberID = System.Configuration.ConfigurationManager.AppSettings["tolunaMemberID"]; //currMemberID = 8000015

Web.Config文件:

<appSettings>
<add key="tolunaMemberID" value="8000015" />
</appSettings>

写入:

Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");//读取配置文件
config.AppSettings.Settings.Remove("tolunaMemberID");//移除该字段
config.AppSettings.Settings.Add("tolunaMemberID", “8000020”);//新添加字段并设置
config.Save();//保存

Web.Config文件:

<appSettings>
<add key="tolunaMemberID" value="8000020" />
</appSettings>

posted @ 2018-12-25 12:09  Didi_Liu  阅读(805)  评论(0编辑  收藏  举报