I've written following code to make changes to the values of AppSettings in the web.config and when I tested it on my dev machine, it works fine. However, after I've copied the page to the production server, changing the values are not updated.
Configuration myConfig = WebConfigurationManager.OpenWebConfiguration("~");
try
{
myConfig.AppSettings.Settings["username"].Value = txtUsername.Text;
myConfig.AppSettings.Settings["password"].Value = txtPassword.Text;
myConfig.AppSettings.Settings["senderNum"].Value = txtSMSCenter.Text;
myConfig.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
lblStatus.Text = "Config updated at: " + DateTime.Now.ToString();
}
catch (ConfigurationException ex)
{
lblStatus.Text = ex.Message;
}
I've allowed write access for Administrator, Network Service and IIS_IUSRS to web.config but still doesn't work.
Any advices?