I used the below code to change the appsetting key value in the web configuration of the application.
private void ChanngeDefaultPassword(string password)
{
try
{
var objConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings");
objConfig.AppSettings.Settings["DEFAULT_PASSWORD"].Value = password;
objConfig.Save();
}
catch (Exception ex)
{
}
}
I am getting error stating
Attempted to perform an unauthorized operation.
This error is thrown in the step to save the configuration changes.