I created a second web config and placed it in a folder:
~/Configuration/OtherConnections.config
My config file looks like:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="serverurl" value="http://serverUrl" />
<add key="UserName" value="myUser" />
<add key="Password" value="XXXXXXX" />
</appSettings>
</configuration>
When I attempt to read the value from one of the items like:
string connectionInfo = ConfigurationManager.AppSettings["UserName"];
I do not get a value back. Is this because the web config is in a folder, or is there something else going on in this web app?
I do not get a value back. Is this because the web config is in a folder ... ?
No, not the folder but the filename. You can use ~/Configuration/Web.config
but then you have to explicity open it:
var config = WebConfigurationManager.OpenWebConfiguration("~/Configuration");
And then to read from it:
string url = config.AppSettings.Settings["serverurl"].Value;
Note that you cannot specify (and thus not change) the actual web.config
file name. Just the folder.
you can have only one web.config
file for each web folder
There are tow options anyway:
In the IIS Manager you need to configure the sub folder as a new application. It uses the web.config file from the running app.
Another option is using a single config file and adding a <location>
section to segment the file to act differently for some folders or files. (which I would suggest more info here)
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