ASP.NET新增、修改、刪除web.config配置資訊

iDotNetSpace發表於2009-12-25
 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部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-623598/,如需轉載,請註明出處,否則將追究法律責任。

相關文章