I need help updating <appsettings> value in the Web.config, I keep getting the following error message:
A configuration file cannot be created for the requested Configuration object.
I've tried with ASP.NET Webform framework 4.0, 4.5, 4.6, 4.7 and neither one works
Here is my code:
protected void btnUpdate_Click(object sender, EventArgs e)
{
try
{
var keyName = this.asetKeyName.Text.Trim();
var keyValue = this.asetKeyValue.Text.Trim();
var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/web.config");
config.AppSettings.Settings[keyName].Value = keyValue;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("web.config");
this.lit_Content.Text = "Successfully Updated.";
}
catch (Exception exm)
{
this.lit_Content.Text = exm.Message.ToString();
Console.WriteLine(exm.Message.ToString());
}
}