当前位置 : 主页 > 网络编程 > net编程 >

.net Web.config工具类

来源:互联网 收集:自由互联 发布时间:2023-09-06
public static class AppConfigUtil { public static string GetAppConfig(string key) { Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); return config.AppSettings.Settings[key].Value; } /// summ


   public static class AppConfigUtil
    {

         public static string GetAppConfig(string key)
        {
            Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
            return config.AppSettings.Settings[key].Value;
        }


        /// <summary>  
        /// 在web.config文件中appSettings配置节增加一对键值对  
        /// </summary>  
        /// <param name="key"></param>  
        /// <param name="val"></param>
        public static void UpdateAppConfig(string key, string val)
        {
            Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
            bool exist = config.AppSettings.Settings.AllKeys.Contains(key);
            if (exist)
            {
                config.AppSettings.Settings.Remove(key);
            }
            config.AppSettings.Settings.Add(key, val);
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }
    }
【本文由:高防cdn http://www.558idc.com/gfcdn.html 复制请保留原URL】
上一篇:IO流之 字节流 & 字符流
下一篇:没有了
网友评论