问题
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?
回答1:
Try to Check this sites;
How to change App.config file run time using C#
Modify web.config appSettings at run time by code behind
How do you modify the web.config appSettings at runtime?
Regards
来源:https://stackoverflow.com/questions/8500683/unable-to-write-appsettings-of-web-config-on-production-server