[英]How to retrieve the value for the Key in the Web.Config using DictionarySectionHandler
如何獲取我將動態獲取的鍵的對應值。 我希望使用系統定義的DictionarySectionHandler來完成從Web.config文件中的自定義構建的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中獲取其各自的Source。 在這方面的任何幫助將不勝感激。
您對domainsource-> domainSource部分的定義有誤。 進一步確保要在元素中定義元素。 然后它應該工作。
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.