[英]How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace?
[英]How can I manipulate appsettings in a web.config on a remote machine using Microsoft.Web.Administration?
我正在使用Microsoft.Web.Administration库在远程计算机上配置web.config。 我已经能够使用Application
对象上的GetWebConfiguration
方法来阅读各节并在GetWebConfiguration
添加新项,但是我遇到了与appSettings相关的问题。 我希望能够读写appsettings部分,但是我似乎找不到找到这种方法的方法,也没有找到一个很好的在线示例。
使用Microsoft.Web.Administration支持吗? 如果没有,是否还有另一个优雅的解决方案? 该解决方案必须能够远程工作。
是的,您应该能够执行以下操作,请注意,我是使用IIS配置编辑器生成的代码,请参阅: http : //blogs.iis.net/bills/archive/2008/06/01/how-do -i-脚本自动化- IIS7,configuration.aspx
using(ServerManager mgr = ServerManager.OpenRemote("Some-Server")) {
Configuration config = mgr.GetWebConfiguration("site-name", "/test-application");
ConfigurationSection appSettingsSection = config.GetSection("appSettings");
ConfigurationElementCollection appSettingsCollection = appSettingsSection.GetCollection();
ConfigurationElement addElement = appSettingsCollection.CreateElement("add");
addElement["key"] = @"NewSetting1";
addElement["value"] = @"SomeValue";
appSettingsCollection.Add(addElement);
serverManager.CommitChanges();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.