开发者

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)
{

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜