我有一个应用程序驻留在虚拟目录中。它在其Web.config
以下设置:从外部程序访问web.config设置
<appSettings>
<add key="SomePath" value="C:\Somepath\whatever"/>
........other settings.........
</appSettings>
我有一个外部运行到需要读取这个值的应用程序的可执行文件:
System.Configuration.Configuration config =
WebConfigurationManager.OpenWebConfiguration("/MyApplicationVirtualDirectory")
as System.Configuration.Configuration;
string path = config.AppSettings.Settings["SomePath"].Value;
这将引发编译错误:
'System.Configuration.ConfigurationElement.this[System.Configuration.ConfigurationProperty]' is inaccessible due to its protection level
我认为这是有道理的,因为虚拟目录中的web.configs包含一些敏感信息,如连接字符串等,但我想检查并确保我没有做有什么不对,并且我的理解是正确的。如果没有,我如何从我的外部可执行文件访问此设置?
我以前多次使用这个问题的答案没有问题:https://stackoverflow.com/questions/21171894/reading-external-configuration-file也许你应该看看另一种方式来分享配置,虽然。 – 2014-11-20 22:12:05