1

我在 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;
        }
4

2 回答 2

2

我不确定您的代码如何适合成员资格和角色提供程序系统,但是您是否尝试过将每个 URL 覆盖放在web.config文件中?

<location path="MyAnonymousPage.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>
于 2009-07-28T11:52:29.400 回答
0

在常规的 ASP.Net 站点中,这可以通过以下代码完成:

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

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

但是,我无法让它在 SharePoint 中按预期运行。

于 2009-08-03T18:09:01.677 回答