在web.config文件中,我有一个第三方的设置部分:阅读第三方配置部分
<configuration>
<configSections>
<sectionGroup name="TheProduct">
<section name="TheSection" type="TheCompany.TheProduct.TheSectionConfigurationHandler, TheCompany.TheProduct, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b1e9bee111e9429c" />
</sectionGroup>
</configSections>
<TheProduct>
<TheSection somevalue="true" />
</TheProduct>
</configuration>
我想从另一个应用程序阅读本节的价值,但是当我尝试找到部分,我总是得到null
。
这里是我的代码:
var config = ConfigurationManager.OpenExeConfiguration(
@"C:\inetpub\wwwroot\TheProduct\web.config"
);
var settings = config.GetSection("TheProduct/TheSection"); // always null
什么是检索配置部分的正确方法是什么?
[编辑]如果调用应用程序,它定义了相同的部分,我可以这样做:
var settings = ConfigurationManager.GetSection("TheProduct/TheSection");
,它的工作。 Mybe我没有用正确的方式打开web.config文件?
您是否在应用程序中提及了“TheCompany.TheProduct,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = b1e9bee111e9429c'? – 2012-03-06 13:08:57
不......实际上,区段处理程序在第三方库中是内部的。我想用反射来读取值。 – 2012-03-06 13:11:33
编辑:我有参考第三方lib ...我只是不能实例化类型我自己 – 2012-03-06 13:14:48