开发者

Retrieving "system.webServer/security/authorization" configuration with Microsoft.Web.Administration API

开发者 https://www.devze.com 2023-01-15 05:05 出处:网络
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.

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.webServe开发者_如何学Gor>
        <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.


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()
0

精彩评论

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