无法在生产服务器上编写web.config的AppSettings

时间:2011-12-14 07:11:52

标签: c# asp.net file permissions web-config

我编写了以下代码来更改web.config中AppSettings的值,当我在dev机器上测试它时,它运行正常。但是,在我将页面复制到生产服务器后,更改值不会更新。

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;
        }

我允许管理员,网络服务和IIS_IUSRS对web.config进行写访问,但仍然无效。

有任何建议吗?

相关问题