Unable read App.config values from Class Library

后端 未结 3 907
慢半拍i
慢半拍i 2021-01-03 05:14

This may be the simple question to answer, but I am struggling to resolve.

I have Web.config with the following values in my Web Application.

         


        
相关标签:
3条回答
  • 2021-01-03 05:27

    You have to merge both configuration sections and place all settings in the main configuration file of your application. In case of the web applciation it would be the web.config.

    0 讨论(0)
  • 2021-01-03 05:32

    While I don't work often with web applications, in my desktop application I often face a similar issue. I've been using the code provided by Daniel Hilgarth https://stackoverflow.com/a/6151688/2212458 to temporarily switch configuration files. The plugin loader can pull in the plugin configuration file and then restore its own.

    0 讨论(0)
  • 2021-01-03 05:34

    The short answer is: you can't. The application using your library won't pay any attention to your app.config. You could use a settings file instead or perhaps go a longer way around, abstract out the configuration manager and have it programmatically read your app.config as an XML file in the application's output directory in order to include its settings. Understandably, neither option is ideal.

    0 讨论(0)
提交回复
热议问题