I have a web application deployed in IIS. This web application consumes a library that wants to access Web.config.
Example: Foo.dll is a web application deployed in IIS Foo.Utility.dll is consumed by Foo.dll
Foo.Utility namepsace has a code snippet that wants to access web.config from a Foo application and read the configuration values
Configuration config = WebConfigurationManager.OpenWebConfiguration(null); string cacheDir = config.AppSettings.Settings["abc"].Value;
Currently config.FilePath = C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Config \ web.config
Changed my code:
Configuration config = WebConfigurationManager.OpenWebConfiguration(Assembly.GetCallingAssembly().Location); string cacheDir = config.AppSettings.Settings["abc"].Value;
Now my Assembly.GetCallingAssembly (). Location: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET files \ root \ 62f5c902 \ 849205ff \ assembly \ dl3 \ c28d4647 \ 10e128d3_7449d001 \ foo.dll
Can someone help me understand how to read web.config from where my application is deployed using IIS?
For more information, or if the question is not clear, give a comment below. Will be updated.
source share