I am trying to read the keys from the Web.config
file in a different layer than the web layer (Same solution)
Here is what I am trying:
string userName = System.Configuration.ConfigurationManager.AppSettings["PFUserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["PFPassWord"];
And here is my appSettings
in the Web.config
file:
<configuration>
....
<appSettings>
<add key="PFUserName" value="myusername"/>
<add key="PFPassWord" value="mypassword"/>
</appSettings>
....
</configuration>
When I debug the code username
and password
are just null
, so it is not getting the value of the keys.
What am I doing wrong to read these values?
Full Path for it is
There will be two Web.config files. I think you may have confused with those two files.
Check this image:
In this image you can see two Web.config files. You should add your constants to the one which is in the project folder not in the views folder
Hope this may help you
If the caller is another project, you should write the config in caller project not the called one.
Also you can try this line to get string value from
app.config
file.Sorry I've not tested this but I think it's done like this: