Reputation: 9281
I need to update a remote Web.config file and I currently have access to the application via the ServerManager
object inside of the Microsoft.Web.Administration
assembly like so:
ServerManager serverManager = ServerManager.OpenRemote("::1");
Configuration configuration = serverManager.GetWebConfiguration("Default Web Site", "/Application.Name");
Is there anyway I'm able to retrieve the path of the Web.config from this object so I can load it into System.Xml.Linq.XDocument
and modify it?
My initial thought was to use ConfigurationElementCollection appSettings = configuration.GetSection("appSettings").GetCollection();
but I'm unable to access the configuration data that I need to modify using this method so need to use XDocument
instead.
Upvotes: 3
Views: 1560
Reputation: 9281
I eventually found it. It looks like the only way to access it is like so:
ServerManager manager = ServerManager.OpenRemote("::1");
string physicalPath = manager.Sites[siteName].Applications[virtualDirPath].VirtualDirectories[0].PhysicalPath
string webConfigLocation = Path.Combine(physicalPath, "web.config");
Upvotes: 3