码迷,mamicode.com
首页 > Web开发 > 详细

asp.net修改web.config文件

时间:2014-07-27 21:38:05      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

        private void UpdateConfigFile()
        {
            var cfg = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            if (cfg.ConnectionStrings.ConnectionStrings["masterConnString"] == null)
            {
                var elCon = cfg.ConnectionStrings.ConnectionStrings["ElectricConnString"];
                cfg.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings { Name = "masterConnString", ProviderName = "System.Data.SqlClient", ConnectionString = elCon.ConnectionString.Replace("Electric", "master") });
                cfg.Save();
            }
        }

 

asp.net修改web.config文件

标签:

原文地址:http://www.cnblogs.com/shiningrise/p/3871153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!