关于修改Web配置文件的方法记录

      以前都是直接解析Web.config来操作,现在发现可以这样做,      

       //打开配置文件   
       Configuration   config   =   WebConfigurationManager.OpenWebConfiguration("~");   
      //获取appSettings节点   
      AppSettingsSection   appSection   =   (AppSettingsSection)config.GetSection("appSettings");   
      //删除appSettings节点中的元素   
      appSection.Settings.Remove("addkey1");   
      //修改appSettings节点中的元素   
      appSection.Settings["addkey2"].Value   =   "Modify   key2's   value";   
      config.Save();       

posted @ 2009-07-21 14:50  架构师聊技术  阅读(259)  评论(0)    收藏  举报