系統。配置。配置c =系統。web . configuration . webconfigurationmanager . open web configuration(“~“);
c.connection strings . connection strings . clear();
ConnectionStringSettings s = new ConnectionStringSettings();
南ProviderName =“System。data . OleDb“;
南ConnectionString =“Provider = Microsoft . oledb . jet . 4.0;數據源= c:\ \ ABC . MDB“;
南name =“my access“;
c.connection strings . connection strings . add(s);
c.save();
但是,出於安全考慮,不允許使用配置類修改Web.config。
它只能以操作xml對象的形式進行修改。
XML document doc = new XML document();
醫生。load(“web . config“);
XmlNode node = doc。document element . SelectSingleNode(“appSettings“);
節點。SelectSingleNode(“descendant::add【@ key =‘Value _ Inform‘】“)。屬性【1】。value =“111“;
醫生。document element . SelectSingleNode(“appSettings“)。InnerXml = node。InnerXml
醫生。save(“web . config“);
盡量不要修改web.config文件。
aspnet_wp進程監視web.config的更改。如果有任何更改,所有會話都將重置,因為這將導致web應用程序重新啟動並降低性能。
但是,不建議動態修改web.config的值,因為這將導致web應用程序重新啟動並降低性能。