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

1、导入命名空间​

using System.Configuration;

using System.Web.Configuration ;

2、输入代码​

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

//保存在配置文件中

TextBox1.Text= WebConfigurationManager.AppSettings["xdsj"].ToString();

TextBox2.Text= WebConfigurationManager.AppSettings["zygs"].ToString();

}​

}

protected void Button1_Click(object sender, EventArgs e)

{

string xdsj = TextBox1.Text;

string zygs = TextBox2.Text;

int i;

//保存在配置文件中

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

//增加

config.AppSettings.Settings.Add("key", "Name");

//修改

config.AppSettings.Settings["xdsj"].Value = xdsj;

config.AppSettings.Settings["zygs"].Value = zygs;

config.Save();

}

posted @ 2015-09-23 14:07  xashxsy  阅读(425)  评论(0编辑  收藏  举报