0

I have next scenario:

  • One Class Library (For example called Utilities) using one app.config
  • One General Site Web application using web.config and applications with web.config each one.

I need to insert an appsettings called "XXX". obviouslly should set in the Site web.config.

The Utilities library is called in all application that I have inside the Site, then I should set the appsettings key in each web.config (something confusing).

How can I set the key inside app.config and read it? ConfigurationManager only read from Web.Config and I would like to read app.config keys inside Utilites.

Is it possible?

Dave
  • 7,028
  • 11
  • 35
  • 58
  • If i am not wrong, you can keep all secrets in web.config of the solution itself, mostly the web one.keeping in Multiple web.config is not required. – lokanath das Sep 17 '18 at 12:22
  • then I cant use app.config inside Utilities right? Utilities is read in all the application – Dave Sep 17 '18 at 12:30
  • I had simillar issue, while i was trying to access some of the keys but was unable to got Null from app.config. So once i placed it inside the web.config it started working.. but yes you are right, this is bit confusing one. – lokanath das Sep 17 '18 at 12:34
  • could be cool to use app.config of the class library – Dave Sep 17 '18 at 12:40
  • ConfigurationManager can read from app.config or web.config. However, it will only read from one or the other depending on whether you're in a web project or not. It won't do both at the same time unless you [tell it to](https://stackoverflow.com/questions/505566/loading-custom-configuration-files). But still, it's better to just put the settings directly in the web.config of the consuming application so you don't have to mess with copying the app.config around. – mason Sep 17 '18 at 13:14

1 Answers1

-1

Hi I found the solution:

if yu want to get the properties of app.config you can use:

var value = Properties.Settings.Default.keyName
Dave
  • 7,028
  • 11
  • 35
  • 58