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】