我需要更新一个远程Web.config文件,我目前可以通过ServerManager
程序集中的Microsoft.Web.Administration
对象访问该应用程序,如下所示:
ServerManager serverManager = ServerManager.OpenRemote("::1");
Configuration configuration = serverManager.GetWebConfiguration("Default Web Site", "/Application.Name");
我是否能够从此对象检索Web.config的路径,以便将其加载到System.Xml.Linq.XDocument
并进行修改?
我最初的想法是使用ConfigurationElementCollection appSettings = configuration.GetSection("appSettings").GetCollection();
,但我无法使用此方法访问我需要修改的配置数据,因此需要使用XDocument
。
答案 0 :(得分:3)
我终于找到了它。看起来访问它的唯一方法是:
ServerManager manager = ServerManager.OpenRemote("::1");
string physicalPath = manager.Sites[siteName].Applications[virtualDirPath].VirtualDirectories[0].PhysicalPath
string webConfigLocation = Path.Combine(physicalPath, "web.config");