Unable to write AppSettings of web.config on production server

心不动则不痛 提交于 2019-12-24 10:17:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!