我需要更新一个远程Web.config文件,目前我可以通过Microsoft.Web.Administration程序集中的ServerManager对象访问应用程序,如下所示:
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。
发布于 2013-12-16 11:21:36
我终于找到了。它看起来是访问它的唯一方法,如下所示:
ServerManager manager = ServerManager.OpenRemote("::1");
string physicalPath = manager.Sites[siteName].Applications[virtualDirPath].VirtualDirectories[0].PhysicalPath
string webConfigLocation = Path.Combine(physicalPath, "web.config");https://stackoverflow.com/questions/20567288
复制相似问题