1. 程式人生 > >如何修改Web.Config裡面的值

如何修改Web.Config裡面的值

0、先新增

<add key="MAXNUM" value="6" />

1、讀取值

string maxNum = ConfigurationManager.AppSettings["MAXNUM"];

2、儲存值

Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettings = config.AppSettings;
appSettings.Settings["MAXNUM"].Value = nCount.ToString();
config.Save();