实现了一个文件管理项目,它运行时需要在web.config内配置路径参数。我想实现当在网站项目内引用此项目时,能修改网站的Web.config文件。不知道在什么时机,执行修改web.config的操作。
我看当引用System.Web.Extension时它就会自动修改Web.config ,不知道它是怎么实现的。

解决方案 »

  1.   

    Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
    config.AppSettings.Settings.Clear();
    config.AppSettings.Settings.Add("keyname", "c%o@f#f@e(e%f^o*x");其他具体操作应该自己就能找到了吧
      

  2.   

    Configuration config  
    = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
    AppSettingsSection appSettings = (AppSettingsSection) config.GetSection("appSettings");
    string[] appKeys = appSettings.Settings.AllKeys;
    for (int i = 0; i < appSettings.Settings.Count; i++)
    {}FileInfo fileinfo = new FileInfo(Context.Parameters["targetdir"] + "\\web.config");
      XmlDocument xmldocument=new XmlDocument();
      xmldocument.Load(fileinfo.FullName);
      foreach(XmlNode node in xmldocument.SelectSingleNode("appSettings").ChildNodes)
      {   
      if (node.Name == "add")
      {   
      if (node.Attributes.GetNamedItem("key").Value == "connString")
      {
      node.Attributes.GetNamedItem("value").Value= ""; 
      }   
      }   
      }
      xmldocument.Save(fileinfo.FullName);
      

  3.   

    在vs里添加引用时就修改web.config的话貌似不那么容易,俺是不会
    好多组件也不会还得手动修改配置
    你可以自己写个配置文件加密一下,干嘛非写到web。config里
      

  4.   


    配置管理是很麻烦,可以用微软ent lib一个什么block里的程序辅助管理,我是自己写个的,而且除了历史遗留项目(不知道为什么,早期人都特爱些配置文件,显见很牛13似的),现在能不用配置坚决不用。
    相对那些做java spring的,这点配置都是小case了。