简体   繁体   English

从具有web.config的服务调用DLL时如何读取DLL自己的app.config?

[英]How to read DLL's own app.config when it's called from a service that has a web.config?

I have a WCF service that calls into a DLL. 我有一个调用DLL的WCF服务。 The service has a web.config and the DLL has an app.config. 该服务具有一个web.config,而DLL具有一个app.config。 I've written a custom app config section thanks to this question for the DLL. 由于这个问题 ,我已经编写了一个自定义应用程序配置部分。 However, in the DLL when I make a call to ConfigurationManager.GetSection("...") it tries to read from the service's web.config. 但是,在DLL中,当我调用ConfigurationManager.GetSection("...")它将尝试从服务的web.config中读取。

How can I set it up so that the DLL reads from it's app.config while the service reads from it's web.config? 如何设置它,以便DLL从其app.config中读取,而该服务从其web.config中读取?

EDIT: It seems that when my I debug my service, my DLL gets copied to a strange temp folder (C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Temporary ASP.NET Files\\root\\f4d2cdd1\\a59eb1c1\\assembly\\dl3\\7c7f438f\\b42518b4_f8f2cf01) but my DLL's config does not. 编辑:似乎当我调试服务时,我的DLL被复制到一个奇怪的临时文件夹(C:\\ Windows \\ Microsoft.NET \\ Framework \\ v4.0.30319 \\ Temporary ASP.NET Files \\ root \\ f4d2cdd1 \\ a59eb1c1 \\ assembly \\ dl3 \\ 7c7f438f \\ b42518b4_f8f2cf01),但我的DLL的配置却没有。 If I copy the config there by hand, I can use OpenMappedExeConfiguration to read it. 如果手动将配置复制到那里,则可以使用OpenMappedExeConfiguration进行读取。 A regular call to ConfigurationManager continues to read the web.config even if the app.config is present. 即使存在app.config,对ConfigurationManager的常规调用也会继续读取web.config。

I can't move the config settings from the app.config to the web.config because this DLL is shared between a WCF service and a REST service. 我无法将配置设置从app.config移到web.config,因为此DLL在WCF服务和REST服务之间共享。 I want them coming to a single DLL that offers core functionality for both. 我希望它们进入一个为两者提供核心功能的DLL。 The DLL should read it's own config file and not either of the web.configs so that there's no chance of one service getting different values than the other. DLL应该读取它自己的配置文件,而不要读取任何一个web.configs,这样一来,一个服务就不可能获得与另一个服务不同的值。

If the call originates from web service, or anything that runs off web server such as IIS, then it will read only from web.config. 如果调用源自Web服务或运行于Web服务器之外的任何内容(例如IIS),则它将仅从web.config中读取。 If you are running console app or any app that does not run on web server then app.config will be used. 如果您正在运行控制台应用程序或任何不在Web服务器上运行的应用程序,则将使用app.config。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM