Configuration config = WebConfigurationManager.OpenWebConfiguration("~");//这里一定要用~,否则会出现‘无法为请求的配置对象创建一个配置文件’,‘不能使用相对虚拟路径’等问题
AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
string _activityID = ActivityIDTextBox.Text;
if (section.Settings["ActivityID"] == null)
{
section.Settings.Add("ActivityID", _activityID);
}
else
{
section.Settings["ActivityID"].Value = _activityID;
}
config.Save(ConfigurationSaveMode.Modified);