Yes it's possible but should be done with caution. The example I've had to do this in is as part of an installer project, so the web.config wasn't in use and the app was being installed for the first time.
Something like this could be adapted for your purpose:
private string ConfigPath { get { return Path.Combine(targetDirectory.Substring(0, targetDirectory.LastIndexOf("\\") - 1), "Web.Config"); } }
XmlDocument doc = new XmlDocument();
doc.Load(this.ConfigPath);
XmlNode MyNode = doc.SelectSingleNode("configuration/appSettings/add[@key='YourKey']");
MyNode.Attributes["value"].Value = YourValue;
doc.Save(this.ConfigPath);
Alternatively you can use the ConfigurationManager like this to modify an existing key:
var config = System.Web.Configuration.WebConfigurationManager
.OpenWebConfiguration("~/web.config");
config.AppSettings.Settings["Your Key"].Value = "Your Value";
config.Save(ConfigurationSaveMode.Modified);