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:
Also you can try this line to get string value from app.config
file.
var strName= ConfigurationManager.AppSettings["stringName"];
Sorry I've not tested this but I think it's done like this:
var filemap = new System.Configuration.ExeConfigurationFileMap();
System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(filemap, System.Configuration.ConfigurationUserLevel.None);
//usage: config.AppSettings["xxx"]
If the caller is another project, you should write the config in caller project not the called one.
Full Path for it is
System.Configuration.ConfigurationManager.AppSettings["KeyName"]
var url = ConfigurationManager.AppSettings["ServiceProviderUrl"];
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