zoukankan      html  css  js  c++  java
  • 实时修改和读取webconfig

            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中配置的注释信息都没有了

  • 相关阅读:
    优秀个人博客
    redis 3.0 集群__监控警报工具(sentinel)
    redis 3.0 集群__hashTag
    shell__常用命令__sed
    shell__常用命令__grep
    shell__常用命令__awk
    shell 常用命令集合
    redis 3.0 集群__配置文件详解(常用配置)
    redis 3.0 集群__故障测评
    tcp 建立连接的三次握手,以及关闭连接的4次挥手
  • 原文地址:https://www.cnblogs.com/wangdongjie0101/p/2773775.html
Copyright © 2011-2022 走看看