I can access and modify the contents of a <location> tag in web.config, starting from:
Configuration config = WebConfigurationManager.OpenWebConfiguration(virtualFolderPath);
ConfigurationLocationCollection locations = config.Locations;
then for each location:
Configuration thisConfig = location.OpenConfiguration();
However, I cannot see any way to add a new <location>, is that possible?
The web.config is a legal XML document. So, other considerations aside, there is nothing to stop you from loading it and using either XMLDocumment / XPath or XDocument methods to modify and save the file.
A ConfigurationLocationCollection is derived from a System.Collections. ReadOnlyCollectionBase which is read-only. So using the configuration API's as they are just now this is not possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With