How to Update (Add/Modify/Delete) keys in AppSettings section of web.config at runtime

前端 未结 4 746
闹比i
闹比i 2021-01-12 23:11

I like to Update keys/Values defined in AppSettings section of Web.config at runtime. however I DO NOT want to actually save them to Web.conf

4条回答
  •  Happy的楠姐
    2021-01-12 23:42

    You need to make use of WebConfigurationManager.OpenWebConfiguration()

    Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
    config.AppSettings.Settings.Remove("Variable");
    config.AppSettings.Settings.Add("Variable", "valyue");
    config.Save();
    

提交回复
热议问题