2009-07-28 323 views
1

我已经在ASP.Net中创建了一个身份验证模块,但是我不希望在验证模块中的逻辑被执行,如果资源配置为匿名访问,因为逻辑很贵。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; 
     } 
+0

对不起,我不清楚。该页面已根据您的描述进行配置。但是,我有一个自定义身份验证模块。如果页面配置为允许用户=“*”或允许用户=“?”,我想在知道用户身份之前退出模块逻辑。 – complexcipher 2009-07-28 15:01:24

回答

2

我不知道你的代码如何适应成员资格和角色提供系统,但你有没有试图把每个网址覆盖在web.config文件?

<location path="MyAnonymousPage.aspx"> 
    <system.web> 
     <authorization> 
      <allow users="*"/> 
     </authorization> 
    </system.web> 
</location> 
0

在常规的ASP.Net网站这可以用下面的代码来完成:

IPrincipal anonUser = new GenericPrincipal(new GenericIdentity(string.Empty, string.Empty), new string[0]); 

bool allowAnon = UrlAuthorizationModule.CheckUrlAccessForPrincipal(requestPath, anonUser, "get"); 

不过,我有得到它像预期的那样在SharePoint中的问题。