Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ConfigurationManager in web apps

As far as I understand, I should use System.Configuration.ConfigurationManager to read app settings in desktop applications, and System.Web.Configuration.WebConfigurationManager to do the same thing in web applications. This is what MSDN says.

I am developing a component that will be deployed to both desktops and web servers, so I am trying to make configuration logic independent of the platform. To my surprise, I discovered by accident that app settings are read correctly by using System.Configuration.ConfigurationManager on a web server.

I have two related questions:

  1. Can anyone confirm that this works systematically?
  2. What are the limitations or risks of using System.Configuration.ConfigurationManager on web applications?

Thanks.

like image 881
CesarGon Avatar asked Jan 31 '26 20:01

CesarGon


1 Answers

MSDN says that WebConfigurationManager is the preferred way to work with configuration files in web applications.

In web applications, configuration can be inherited from a web.config file in a parent virtual directory: WebConfigurationManager will handle such inherited settings properly, which I believe isn't the case for ConfigurationManager.

Of course, if your application does not inherit such settings (e.g. is always at the root of a web site), this is not relevant to you.

like image 177
Joe Avatar answered Feb 03 '26 10:02

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!