簡體   English   中英

如何使用Microsoft.Web.Administration在遠程計算機上的web.config中操縱appsettings?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM