我在 ASP.Net 中创建了一个身份验证模块,但如果资源配置为匿名访问,我不希望执行身份验证模块中的逻辑,因为该逻辑很昂贵。
需要认证的页面与不需要认证的页面位于同一目录中。我无法控制这一点。是否有一种简单的方法可以确定资源配置为在 URLAuthorizationModule 之前允许匿名访问?
目前,我正在做以下“感觉”正确的事情。任何帮助,将不胜感激。
public static bool AllowEveryone()
{
bool rslt = false;
AuthorizationSection config = (AuthorizationSection)WebConfigurationManager.GetSection("system.web/authorization");
if (config.Rules != null && config.Rules.Count > 0)
{
AuthorizationRule r = config.Rules[0]; //doing this based on implementation of urlauthorization module in reflector...
if (r.Action == AuthorizationRuleAction.Allow && r.Users.Contains("*"))
{
return true;
}
//todo: check for allow anon ? case
}
return rslt;
}