Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a location element in web.config programmatically (using ConfigurationLocation for example)

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?

like image 922
Barry Avatar asked May 29 '26 23:05

Barry


2 Answers

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.

like image 57
Peter Bromberg Avatar answered Jun 01 '26 13:06

Peter Bromberg


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.

like image 31
Kev Avatar answered Jun 01 '26 12:06

Kev