I have a three tier web app that produces three separate dlls:
- Web.UI.dll
- Web.Application.dll
- Web.DAL.dll
Both Web.Application.dll and Web.DAL.dll have their own app.configs. I need to access a specific setting that lives in web.config. I am using the following code:
[CacheUtil.cs]
string cacheName = ConfigurationManager.AppSettings.Get("CacheName");
I have verified that this setting exists. So, why then, when I run am I getting NULL? Does CacheName need to exist in all of .config files?
Here is the setting in web.config:
<appSettings>
<add key="CacheName" value="staging"/>
FYI, CacheUtil is a singleton that is lazy initialized upon first access. First access is happening in the DAL.dll project.
Thanks!
Only
web.configis being read. The other config files (Web.Application.dll.configandWeb.DAL.config) are not read.Config is not attached to libraries; only to the ultimate executable being run (the
AppName.exe.configorweb.config)Projects in Visual Studio that produce an EXE can have an
app.configfile, and this file is treated specially upon build; It is renamed toProgramName.exe.configand copied to the output directory.app.configin class library or Web application projects will have no effect.