.net代码修改webconfig

   /// <summary>
        /// 写入web.config
        /// </summary>
        /// <param name="item">appSettings等</param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void WriteConfig(string item, string key, string value)
        {
            if (item == "")
            {
                item = "appSettings";
            }
            Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
            AppSettingsSection appSection = (AppSettingsSection)config.GetSection(item);
            if (appSection.Settings[key] == null)
            {
                appSection.Settings.Add(key, value);
                config.Save();
            }
            else
            {
                appSection.Settings.Remove(key);
                appSection.Settings.Add(key, value);
                config.Save();
            }
        }

 

posted @ 2018-11-08 10:44  Hi!宋先生  阅读(236)  评论(0编辑  收藏  举报