This function mainly uses XMLDocument to parse Web.config. And use the selectsinglenode () method to locate the configuration section you want to modify. It is important to pay attention to the last program to save (), so your APSNET account must have write permissions to Web.config.
---------------------------------------------------------------------------------------------------------------------------------------
// / Modify the value attribute in the addset in the web.config file appSettings configuration section
/// summary>
///
/// Note, after calling the function, the entire web application will be restarted, resulting in all current sessions lost
/// remarks>
/// Key param> to modify
/// Modified Value param>
///
///
Public void modify (String Key, String Strigue)
{
String xpath = "/ configuration / appsettings / add [@ key = '?']";
XMLDocument Domwebconfig = New XmLDocument ();
DomWebconfig.Load (httpContext.current.server.mappath ("Web.config"));
XMLNode AddKey = DomWebconfig.selectsinglenode ((xpath.replace ("?", Key)));
IF (addKey == NULL)
{
Throw new ArgumentException ("No
}
Addkey.attributes ["value"]. innerText = STRVALUE;
Domwebconfig.save (httpContext.current.server.mappath ("Web.config"))))
}