怎么弄?对Web.Config的节点 进行增加,删除,修改?

解决方案 »

  1.   

    你想達到什麽效果?
    建議用xml檔案來放你要進行“增、刪、改”的數據。
      

  2.   

    try
      {
      FileInfo fileinfo = new FileInfo(Context.Parameters["targetdir"] + "\\web.config");
      if (!fileinfo.Exists)
      {
      throw new InstallException("没有找到配置文件");
      }
      XmlDocument xmldocument=new XmlDocument();
      xmldocument.Load(fileinfo.FullName);
      Boolean FoundIt = false;
       
      foreach(XmlNode node in xmldocument.SelectSingleNode("appSettings").ChildNodes)
      {   
      if (node.Name == "add")
      {   
      if (node.Attributes.GetNamedItem("key").Value == "connString")
      {
      node.Attributes.GetNamedItem("value").Value= String.Format("Persist Security Info=False;Data Source={0};Initial Catalog={1};User ID={2};Password={3};Packet Size=4096;Pooling=true;Max Pool Size=100;Min Pool Size=1",Context.Parameters["server"],Context.Parameters["dbname"], Context.Parameters["user"], Context.Parameters["pwd"]);
      FoundIt= true;   
      }   
      }   
      }
       
      if (!FoundIt)
      {   
      throw new InstallException("web.Config 文件没有包含connString连接字符串设置");
      }   
      xmldocument.Save(fileinfo.FullName);
      }
      catch(Exception ex)
      {
      throw ex;
      }   
      }
    config 操作
      

  3.   

    web.config进行增加修改删除的示例
      

  4.   

    config里面其实就是XML格式。也就是对XML进行增删改
      

  5.   

    操作WebConfig就是对XML文件的操作.
    另问:为什么要操作webconfig?是否频繁?
      

  6.   

    對webconfig修改?
    那你的Session 緩存 怎麼辦?
      

  7.   

    每改一次web。config。网站就重启一次。什么要求需要这样玩???
      

  8.   

    建议还是另外用个config文件来执行你这些操作。