How can I make a .NET class library read its own configuration file?

前端 未结 7 812
予麋鹿
予麋鹿 2020-12-13 15:10

I have a .NET class library that provides a set of helper functions that are used by several Web Services. This class library must store a single setting, specifically, a co

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 15:55

    You can read the configuration settings of the class library from the hosting application's web.config or app.config.

    If the class library is referenced in a console application, put the settings, the class library needs, in the app.config of the console application (say under appSettings) and read it from the class library using ConfigurationManager under System.Configuration.

    If the class library is referenced in a web application, put the settings the class library needs in the web.config of the web application (say under appSettings) and read it from the class library using ConfigurationManager under System.Configuration.

提交回复
热议问题