I need to read data from both app.config and web.config. My class will have read/write/update methods wrapped in a dll which will be used both by an application (exe) and by a web application. I need to make sure that i access the caller's default configuration file.
For app.config,
Configuration config = ConfigurationManager
.OpenExeConfiguration(ConfigurationUserLevel.None);
works fine.
What would be the equivalent code for web.config?
(P.S.: I read that
Configuration config = WebConfigurationManager
.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath)
works and some say that
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
would work. Which of these actually works and is more general? Or is there any other better alternative?