如何使用 DictionarySectionHandler 检索 Web.Config 中的键的值
How to retrieve the value for the Key in the Web.Config using DictionarySectionHandler
如何获取我将动态获取的键的对应值。我希望使用系统定义的 DictionarySectionHandler 来完成这项工作,从我在 Web.config 中自定义构建的配置部分获取数据文件
Web.Config
中的代码块
<section name="domainsource" type="System.Configuration.DictionarySectionHandler"/>
<domainSource>
<add key="0" value="170" />
<add key="1" value="171" />
<add key="2" value="172" />
<add key="3" value="173" />
<add key="12" value="174" />
</domainSource>
我希望从 Web.Config
中检索数据的主 cs 文件中的源代码
Hashtable statusCodes = ConfigurationManager.GetSection("domainSource") as Hashtable;
vDomainSource = statusCodes[vDomainID];
这就是我卡住的地方 vDomainID 的值是 0/1/2/3/12,基于这个值我需要从 Web.Config 中获取其各自的源。非常感谢这方面的任何帮助。
您在域源 -> 域源部分的定义中有拼写错误。进一步确保元素是在元素中定义的。然后它应该工作。
<configuration>
<configSections>
<section name="domainSource" type="System.Configuration.DictionarySectionHandler"/>
</configSections>
<domainSource>
<add key="0" value="170" />
<add key="1" value="171" />
<add key="2" value="172" />
<add key="3" value="173" />
<add key="12" value="174" />
</domainSource>
</configuration>
如何获取我将动态获取的键的对应值。我希望使用系统定义的 DictionarySectionHandler 来完成这项工作,从我在 Web.config 中自定义构建的配置部分获取数据文件
Web.Config
中的代码块<section name="domainsource" type="System.Configuration.DictionarySectionHandler"/>
<domainSource>
<add key="0" value="170" />
<add key="1" value="171" />
<add key="2" value="172" />
<add key="3" value="173" />
<add key="12" value="174" />
</domainSource>
我希望从 Web.Config
中检索数据的主 cs 文件中的源代码Hashtable statusCodes = ConfigurationManager.GetSection("domainSource") as Hashtable;
vDomainSource = statusCodes[vDomainID];
这就是我卡住的地方 vDomainID 的值是 0/1/2/3/12,基于这个值我需要从 Web.Config 中获取其各自的源。非常感谢这方面的任何帮助。
您在域源 -> 域源部分的定义中有拼写错误。进一步确保元素是在元素中定义的。然后它应该工作。
<configuration>
<configSections>
<section name="domainSource" type="System.Configuration.DictionarySectionHandler"/>
</configSections>
<domainSource>
<add key="0" value="170" />
<add key="1" value="171" />
<add key="2" value="172" />
<add key="3" value="173" />
<add key="12" value="174" />
</domainSource>
</configuration>