2012-09-10 84 views
3

在web配置授权规则我有这样几个基于位置的授权规则:获取从web.config中

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

+1

什么是你想干什么就问这个? – freebird

+0

我正尝试为anonymou允许的页面应用自定义授权 – Sane

+0

只是想一想,您是否已经查看了WIF ClaimsAuthN/ClaimsAuthZ管理器来封装您的授权逻辑? –

回答

-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/