Using ASP.NET under .NET 2.0, is it possible to get/set AppSettings in a web.config in a sub-directory, from a page in the root directory? When I say “set”, I do not need a permanent setting of the value, just simply updating the value in memory is sufficient.
I have a web application which has the standard root web.config file, which has system wide configuration settings.
The application also has a number of sub-directories, each one being a separate part of the system, and each having their own web.config file containing configurations that are only necessary for that particular section. (All code within these sections is also built under their own individual NameSpace.)
Is it possible for code within the root directory to get or set an individual <add key="" value=""/> configuration setting from a sub-directory?
So, for example, if I call a page in the root of the web application (e.g. ~/Default.aspx) could it somehow manually lookup an individual configuration value from the ~/Section1/web.config file?
My guess this cannot be done, but I wanted to ask here first
One thought I had – that I’ve tried but doesn’t work – was to have a UserControl within each section with public properties to get the values. Then dynamically load the control from with the root page code and call a property to get the value. However, even though the UserControl is hosted with in the sub-directory, and is part of the sub-directory namespace, it is still not picking up the web.config settings within that sub-directory.
It can’t be done, its one of the main limitations.
for some more information (as well as clarification on my statement) have a look Here: Working with more than one web.config… – the author mentions this limitation in his last paragraph before the comments.
Here is another great resource – 10 things you should know about web.config inheritance