System.Configuration.ConfigurationSettings.AppSettings["DefaultClientID"]="XXX"

解决方案 »

  1.   

    web.config一般是不能写的,但可以通过读取 web.config文件,就像读取XML文件一样。
    string filename=Server.MapPath("../") + @"\web.config";
    XmlDocument  xmldoc= new XmlDocument();
    xmldoc.Load(filename); XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
    foreach(XmlElement element in topM)
    {
    if(element.Name.ToLower()=="appsettings")
    {
    XmlNodeList _node = element.ChildNodes;
    if ( _node.Count >0 )
    {
    _node[0].Attributes["value"].InnerXml=txtConnectionString.Text;
    _node[1].Attributes["value"].InnerXml=ddlTime1.SelectedItem.Text;

    }
    }
    }
    xmldoc.Save(filename);
    这是写web。config的代码。但这会影响整个系统。