ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ASP.NET添加、修改、删除web.config配置信息

ASP.NET添加、修改、删除web.config配置信息

原创 Linux操作系统 作者:iDotNetSpace 时间:2009-12-25 14:44:16 0 删除 编辑
 1 using System;

    2 using System.Data;

    3 using System.Configuration;

    4 using System.Collections;

    5 using System.Web;

    6 using System.Web.Security;

    7 using System.Web.UI;

    8 using System.Web.UI.WebControls;

    9 using System.Web.UI.WebControls.WebParts;

   10 using System.Web.UI.HtmlControls;

   11 using System.Xml;

   12 using study.pctoday.net.cn 

   13 public partial class Default2 : System.Web.UI.Page

   14 {

   15     protected void Page_Load(object sender, EventArgs e)

   16     {

   17         Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

   18 

 

 

   19         //操作appSettings

   20         AppSettingsSection appseting = (AppSettingsSection)config.GetSection("appSettings");

   21         appseting.Settings["web"].Value = "郑少群";            //修改设置

   22         appseting.Settings.Add("name", "郑少群");               //增加设置

   23 

 

 

 

   24         //操作connectionStrings

   25         ConnectionStringsSection conSection = (ConnectionStringsSection)config.GetSection("connectionStrings");

   26         conSection.ConnectionStrings["constr"].ConnectionString = "htttp://study.pctoday.net.cn/App_Data/shaoqun.mdb";                       //修改设置

   27         conSection.ConnectionStrings["constr"].ProviderName = "System.Data.OleDb";

   28         conSection.ConnectionStrings.Add(new ConnectionStringSettings("constr2", "aaaaa", "System.Data.OleDb"));  //增加设置

   29 

   30         config.Save();

   31     }

   32 }

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-623598/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5766042