3

在网络配置中,我有几个基于位置的授权规则,例如:

<location path="error.aspx">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>
<location path="ResetPassword.aspx">
    <system.web>
        <authorization>
            <allow users="?" />
        </authorization>
    </system.web>
</location>

如何在代码 (ASP.NET) 中获取所有这些规则?

4

1 回答 1

-1

看一下这个:

var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
var section = config.GetSection("system.web/authorization") as AuthorizationSection;

foreach (AuthorizationRule rule in section.Rules)
{
    if (rule.Action.ToString().ToLower() == "allow")
    {
        //TODO
    }
}

深入挖掘 AuthorizationRule 类属性。

你可以在这里阅读更多:http: //lajak.wordpress.com/2012/05/16/read-authorization-section-from-web-config/

于 2014-08-08T08:05:37.847 回答