views:

13

answers:

1

Hi!

I'm trying to use the Microsoft.Web.Administration API to access the 'system.webServer/security/authorization' section (at the current request path) to see if anonymous users ("*") can access.

To do that i'm trying to access the section configuration by:

WebConfigurationManager.GetSection(HttpContext.Current, "system.webServer/security/authorization")

I tried that on a path whose web.config is restricting the access to a specific role, like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
           <authorization>
                <remove users="*" roles="" verbs="" />
                <add accessType="Allow" roles="MyRole" />
           </authorization>
        </security>
    </system.webServer>
</configuration>

For my surprise, the returned object is a ConfigurationSection instance with zero ChildElements.

Why is that?

Thanks in advance.

A: 

After looking at the configuration schema at C:\Windows\System32\inetsrv\config\schema\IIS_schema.xml, I discovered that elements under authorization element are in fact a collection.

This means that to get the collection elements I have to use the GetCollection() method instead of accessing the ChildElements property:

     WebConfigurationManager.GetSection("system.webServer/security/authorization", HttpContext.Current.Request.Path).GetCollection()
Maxolidean