asp.net 修改web.config

 protected void Page_Load(object sender, EventArgs e)
    {
        Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        //操作appSettings
           AppSettingsSection appseting = (AppSettingsSection)config.GetSection("appSettings");
            appseting.Settings["web"].Value = "测试";            //修改设置
           appseting.Settings.Add("name", "测试");               //增加设置
   
 
 
 
           // //操作connectionStrings
           // ConnectionStringsSection conSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
           //conSection.ConnectionStrings["constr"].ConnectionString = "htttp://study.pctoday.net.cn/App_Data/shaoqun.mdb";                       //修改设置
           // conSection.ConnectionStrings["constr"].ProviderName = "System.Data.OleDb";
           //conSection.ConnectionStrings.Add(new ConnectionStringSettings("constr2", "aaaaa", "System.Data.OleDb"));  //增加设置
   
           //config.Save();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        //操作appSettings
        AppSettingsSection appseting = (AppSettingsSection)config.GetSection("appSettings");
        appseting.Settings["web"].Value = "测试";            //修改设置
        appseting.Settings.Add("name", "测试");

        config.Save();
    }

发布了68 篇原创文章 · 获赞 6 · 访问量 11万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览