[英]Dynamically switch the configuration file (web or app config)
I have a web application that refers to a DLL. 我有一个引用DLL的Web应用程序。 This DLL has certain config values, which are normally part of the web.config.
此DLL具有某些配置值,通常是web.config的一部分。
There is a requirement to invoke this DLL under different configurations, from the web application. 需要从Web应用程序在不同配置下调用此DLL。 The DLL is third-party and cannot be changed.
DLL是第三方,无法更改。
Have tried the below and failed. 尝试了以下并失败了。
AppDomain.CurrentDomain.SetData("WEB_CONFIG_FILE", @"Config\\Path")
and switch it back after the call. AppDomain.CurrentDomain.SetData("WEB_CONFIG_FILE", @"Config\\Path")
更改配置,并在通话后将其切换回来。 The problem here is that after the first time, it doesn't load the config section again even if I switch. ConfigurationManager.RefreshSection(@"configuration\\mysection")
to force a refresh. ConfigurationManager.RefreshSection(@"configuration\\mysection")
强制刷新。 This doesn't seem to work and people say this call is buggy in .NET Is there anything else I can do? 还有什么我可以做的吗?
Host the DLL in a separate process and communicate using COM (or .Net remoting or a web service or similar). 在单独的进程中托管DLL并使用COM(或.Net远程处理或Web服务或类似服务)进行通信。
Ie create a host process a.exe using C# (say) which exposes classes as COM objects, the classes in turn calling the DLL methods/classes. 即使用C#(例如)创建一个主机进程a.exe,它将类公开为COM对象,这些类依次调用DLL方法/类。 Register as COM objects.
注册为COM对象。
Then create b.exe the same (but with different CLSIDs). 然后创建相同的b.exe(但具有不同的CLSID)。
You can now have different configuration files for a.exe and b.exe (in different folders), yet both can use the DLL services. 您现在可以为a.exe和b.exe(在不同的文件夹中)配置不同的配置文件,但两者都可以使用DLL服务。
You could also do something similar by having two internal web apps and using SOAP or something to talk to them. 您还可以通过使用两个内部Web应用程序并使用SOAP或其他内容与他们交谈来执行类似操作。
But the bottom line is if the DLL works on web.config, you have to put at least one of them into a separate process in a separate folder. 但最重要的是,如果DLL在web.config上运行,则必须将它们中的至少一个放入单独文件夹中的单独进程中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.