.NET Config Files configSource outside the application directory folder

前端 未结 10 1542
灰色年华
灰色年华 2020-11-28 05:06

I have two applications one a console application and the other an ASP.NET app. They both need to know the same appSettings and connectionStrings. So ideally I would like to

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 05:33

    You can load configuration from an arbitrary location, but it won't be available via the static properties of ConfigurationManager:

    Configuration myConfig = ConfigurationManager.OpenExeConfiguration(path)
    

    (There is an overload that allows multuple files to be specified, to support default/user-roaming/user-local hierarchy.)

    Losing the static properties means all the code needs to be aware of the different configuration.

提交回复
热议问题