如何在aspx运行时修改web.config 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 帮助:System.Configuration其实web.config是一个xml文件,通过System.Xml.XmlDocument 来操作可以任意修改。 //web.config修改appSettings; public void Modify(string key,string strValue) //两个参数:要修改的键值 和 要修改的新值; { string XPath="/configuration/appSettings/add[@key='?']"; XmlDocument domWebConfig=new XmlDocument(); domWebConfig.Load( (HttpContext.Current.Server.MapPath("web.config")) ); XmlNode addKey=domWebConfig.SelectSingleNode( (XPath.Replace("?",key)) ); if(addKey == null) { //throw new ArgumentException("没有找到<add key='"+key+"' value=.../>的配置节"); Response.Write("<script>alert (\"没有找到<add key='"+key+"' value=.../>的配置节\")</script>"); return; } addKey.Attributes["value"].InnerText=strValue; domWebConfig.Save( (HttpContext.Current.Server.MapPath("web.config")) ); } 操作XML就可以了,不过最好不要这样做,否则Session将丢失 我倒是操作过.不过操作要重新登陆..因为默认全部丢失了!~就是读写XML文件的东西!~很,简单 急!一个过滤器的问题? 数组作为数据库的查询条件 寻高手解释asp.net代码,在下是做java的 请教repeater 的itemcreated事件 C#三元运算符问题 C#中如何获得字符串的某一位? Web如何在匿名访问下获得客户端用户信息(如:机器名、登录用户帐号等) 网上空间无法播放SWF文件(SWF透明播放) 关于页面和用户控件中事件如何处理???? 关于线程以及窗口隐藏,求大神解答。 漫谈ERP开发之旅——第四站:一切从偷懒谈起(笑谈) 显示数据库内容?
其实web.config是一个xml文件,通过System.Xml.XmlDocument 来操作可以任意修改。
public void Modify(string key,string strValue) //两个参数:要修改的键值 和 要修改的新值;
{
string XPath="/configuration/appSettings/add[@key='?']";
XmlDocument domWebConfig=new XmlDocument();
domWebConfig.Load( (HttpContext.Current.Server.MapPath("web.config")) );
XmlNode addKey=domWebConfig.SelectSingleNode( (XPath.Replace("?",key)) );
if(addKey == null)
{
//throw new ArgumentException("没有找到<add key='"+key+"' value=.../>的配置节");
Response.Write("<script>alert (\"没有找到<add key='"+key+"' value=.../>的配置节\")</script>");
return;
}
addKey.Attributes["value"].InnerText=strValue;
domWebConfig.Save( (HttpContext.Current.Server.MapPath("web.config")) );
}
就是读写XML文件的东西!~很,简单