在有些情况下,要在代码中读取一种全局变量,把这种全局变量放在web.config是一种常见的手段。
代码
///
/// appSettings等
/// 键
/// 值
public 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);
appSectio来源gaodaima#com搞(代@码网n.Settings.Add(key, value);
config.Save();
}
}
以上就是asp.net代码中修改web.config节点的具体方法的详细内容,更多请关注gaodaima搞代码网其它相关文章!