最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
一个修改web.config中appSettings配置节的函数-Web_Service开发-.NE
时间:2022-07-02 11:13:30 编辑:袖梨 来源:一聚教程网
这个函数主要使用XmlDocument来解析web.config.并用SelectSingleNode()方法来定位要修改的配置节。要注意的是最后程序要Save(),所以,你的apsnet帐号必须对web.config拥有写权限.
--------------------------------------------------------------------------------
///
/// 修改web.config文件appSettings配置节中的Add里的value属性
///
///
/// 注意,调用该函数后,会使整个Web Application重启,导致当前所有的会话丢失
///
/// 要修改的键key
/// 修改后的value
///找不到相关的键
///权限不够,无法保存到web.config文件中
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("没有找到的配置节");
}
addKey.Attributes["value"].InnerText=strValue;
domWebConfig.Save( (HttpContext.Current.Server.MapPath("web.config")) );
}
--------------------------------------------------------------------------------
///
/// 修改web.config文件appSettings配置节中的Add里的value属性
///
///
/// 注意,调用该函数后,会使整个Web Application重启,导致当前所有的会话丢失
///
/// 要修改的键key
/// 修改后的value
///
///
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("没有找到
}
addKey.Attributes["value"].InnerText=strValue;
domWebConfig.Save( (HttpContext.Current.Server.MapPath("web.config")) );
}
相关文章
- 差差漫画-登录入口官网 03-01
- 羞羞漫画免费看-羞羞漫画极速登录 03-01
- 羞羞漫画韩国合集资源-羞羞漫画全网在线读站 03-01
- 哔咔漫画APP会员特别版PicACG解锁全部资源最新版本下载 - 哔咔漫画去广告攻略2024安卓安装入口 03-01
- deepseek电脑版下载-deepseek智能软件 03-01
- Deepseek官网入口-Deepseek最新下载 03-01