ConfigurationManager.AppSettings.Set("MailUser","3" );ConfigurationManager.AppSettings.Set("MailPassword","2");ConfigurationManager.AppSettings.Set("MailEnable","1" );
只能临时保存
实时修改webconfig
protected void Button1_Click(object sender, EventArgs e){Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");AppSettingsSection objAppSettings = (AppSettingsSection)objConfig.GetSection("appSettings");if (objAppSettings != null){objAppSettings.Settings["MailUser"].Value = TextBox_UserName.Text.Trim();objAppSettings.Settings["MailPassword"].Value = TextBox_Password.Text.Trim();objAppSettings.Settings["MailEnable"].Value = TextBox_Enable.Text.Trim();objConfig.Save();LoadConfigData();Response.Write("<script>alert('修改成功!')</script>");}}public void LoadConfigData(){TextBox_UserName.Text = ConfigurationManager.AppSettings.GetValues("MailUser")[0];TextBox_Password.Text = ConfigurationManager.AppSettings.GetValues("MailPassword")[0];TextBox_Enable.Text = ConfigurationManager.AppSettings.GetValues("MailEnable")[0];Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");AppSettingsSection appSection = (AppSettingsSection)objConfig.GetSection("appSettings");TextBox_UserName.Text = appSection.Settings["MailUser"].Value;TextBox_Password.Text = appSection.Settings["MailPassword"].Value;TextBox_Enable.Text = appSection.Settings["MailEnable"].Value;}
同时也有一个问题,,就是原来在webconfig中配置的注释信息都没有了