在网络配置中,我有几个基于位置的授权规则,如:
<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)中获取所有这些规则?
答案 0 :(得分:-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/