我有一个配置文件,例如:
<logonurls>
<othersettings>
<setting name="DefaultEnv" serializeAs="String">
<value>DEV</value>
</setting>
</othersettings>
<urls>
<setting name="DEV" serializeAs="String">
<value>http://login.dev.server.com/Logon.asmx</value>
</setting>
<setting name="IDE" serializeAs="String">
<value>http://login.ide.server.com/Logon.asmx</value>
</setting>
</urls>
<credentials>
<setting name="LoginUserId" serializeAs="String">
<value>abc</value>
</setting>
<setting name="LoginPassword" serializeAs="String">
<value>123</value>
</setting>
</credentials>
</logonurls>
如何读取配置以获取传递的键名值。这是我写的方法:
private static string GetKeyValue(string keyname)
{
string rtnvalue = String.Empty;
try
{
ConfigurationSectionGroup sectionGroup = config.GetSectionGroup("logonurls");
foreach (ConfigurationSection section in sectionGroup.Sections)
{
//I want to loop through all the settings element of the section
}
}
catch (Exception e)
{
}
return rtnvalue;
}
config 是具有来自配置文件的数据的配置变量。