0

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?

user720694
  • 2,035
  • 6
  • 35
  • 57
  • @DavidStratton Question edited. I'm looking to accessing these files on a frequent basis. – user720694 May 17 '13 at 14:20
  • OK. It's not possible to retract a vote to close, so I can't un-do my VTC. However, IF this gets closed, you can flag it for reopening. – David May 17 '13 at 14:29

0 Answers0