Iterate over elements in web.config
Short question this time for a change...
Is there a way to iterate through the "location" elements in a web.config?
<configuration>
...
<location path="some/path">
<system.web>
<authorization users="*" />
</system.web>
</location>
<location path="some/other/path">
<system.web>
<authorization users="?" />
</system.web>
</location>
...
<configuration>
开发者_StackOverflow中文版
... and say have an output of something like:
<table>
<tr>
<td>some/path</td>
<td>authorization: *</td>
</tr>
<tr>
<td>some/other/path</td>
<td>authorization: ?</td>
</tr>
</table>
Cheers :)
By using the ConfigurationLocation class.
You can retrieve your web.config like this:
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/web.config");
From there you can iterate through your locations:
foreach (ConfigurationLocation location in config.Locations)
{
}
精彩评论