国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

修改和獲取web.config或app.config文件appSettings配置節(jié)中的Add里的value屬性 函數(shù)

2019-11-17 03:11:19
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

修改和獲取web.config或app.config文件appSettings配置節(jié)中的Add里的value屬性 函數(shù)

   1:  /// <summary>
   2:  /// 修改web.config或app.config文件appSettings配置節(jié)中的Add里的value屬性
   3:  /// </summary>
   4:  /// <remarks>
   5:  /// 注意,調(diào)用該函數(shù)后,會(huì)使整個(gè)Web application重啟,導(dǎo)致當(dāng)前所有的會(huì)話丟失
   6:  /// </remarks>
   7:  /// <param name="key">要修改的鍵key</param>
   8:  /// <param name="strValue">修改后的value</param>
   9:  /// <exception cref="">找不到相關(guān)的鍵</exception>
  10:  /// <exception cref="">權(quán)限不夠,無(wú)法保存到web.config文件中</exception>
  11:  public static void ModifyAppSettings(string key, string strValue)
  12:  {
  13:      string XPath = "/configuration/appSettings/add[@key='?']";
  14:      xmlDocument domConfig = new XmlDocument();
  15:  
  16:      domConfig.Load(Environment.CurrentDirectory + "/Application1.exe.config");
  17:      XmlNode addKey = domConfig.SelectSingleNode((XPath.Replace("?", key)));
  18:      if (addKey == null)
  19:      {
  20:          throw new ArgumentException("沒(méi)有找到<add key='" + key + "' value=.../>的配置節(jié)");
  21:      }
  22:      addKey.Attributes["value"].InnerText = strValue;
  23:      domConfig.Save(Environment.CurrentDirectory + "/Application1.exe.config");
  24:  
  25:  }
  26:  
  27:  /// <summary>
  28:  /// 獲取web.config或app.config文件appSettings配置節(jié)中的Add里的value屬性
  29:  /// </summary>
  30:  /// <param name="key">要修改的鍵key</param>
  31:  /// <param name="strValue">修改后的value</param>
  32:  /// <exception cref="">找不到相關(guān)的鍵</exception>
  33:  /// <exception cref="">權(quán)限不夠,無(wú)法保存到web.config文件中</exception>
  34:  public static string GetAppSettings(string key)
  35:  {
  36:      string XPath = "/configuration/appSettings/add[@key='?']";
  37:      XmlDocument domConfig = new XmlDocument();
  38:  
  39:      domConfig.Load(Environment.CurrentDirectory + "/Application1.exe.config");
  40:      XmlNode addKey = domConfig.SelectSingleNode((XPath.Replace("?", key)));
  41:      if (addKey == null)
  42:      {
  43:          throw new ArgumentException("沒(méi)有找到<add key='" + key + "' value=.../>的配置節(jié)");
  44:      }
  45:      return addKey.Attributes["value"].InnerText;
  46:  }

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 吴川市| 特克斯县| 海林市| 连城县| 梁山县| 将乐县| 绍兴市| 清涧县| 松阳县| 安阳市| 栾城县| 广丰县| 宜都市| 乃东县| 临城县| 弥勒县| 仁怀市| 洱源县| 松阳县| 蒲城县| 博白县| 南郑县| 绥宁县| 庆元县| 唐山市| 剑阁县| 祁门县| 离岛区| 南陵县| 金山区| 汕尾市| 手游| 阿拉善左旗| 禄丰县| 都江堰市| 澜沧| 托里县| 信宜市| 澄江县| 石河子市| 蚌埠市|