C# Asp.Net身份验证模块
我已经在ASP.Net中创建了一个身份验证模块,但是如果资源配置为匿名访问,我不希望执行身份验证模块中的逻辑,因为该逻辑非常昂贵 在同一目录中,有需要验证的页面与不需要验证的页面。我无法控制这一切。有没有一种简单的方法可以确定资源是否配置为允许在URLAuthorizationModule之前进行匿名访问 目前,我正在做以下“感觉”正确的事情。任何帮助都将不胜感激C# Asp.Net身份验证模块,c#,asp.net,security,authorization,httpmodule,C#,Asp.net,Security,Authorization,Httpmodule,我已经在ASP.Net中创建了一个身份验证模块,但是如果资源配置为匿名访问,我不希望执行身份验证模块中的逻辑,因为该逻辑非常昂贵 在同一目录中,有需要验证的页面与不需要验证的页面。我无法控制这一切。有没有一种简单的方法可以确定资源是否配置为允许在URLAuthorizationModule之前进行匿名访问 目前,我正在做以下“感觉”正确的事情。任何帮助都将不胜感激 public static bool AllowEveryone() { bool rslt
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;
}
我不确定您的代码是否适合成员资格和角色提供程序系统,但您是否尝试过在
web.config
文件中添加每个URL覆盖
<location path="MyAnonymousPage.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
在常规ASP.Net站点中,这可以通过以下代码实现:
IPrincipal anonUser = new GenericPrincipal(new GenericIdentity(string.Empty, string.Empty), new string[0]);
bool allowAnon = UrlAuthorizationModule.CheckUrlAccessForPrincipal(requestPath, anonUser, "get");
但是,我无法使其在SharePoint中按预期运行。很抱歉,我不清楚。已根据您的说明配置该页面。但是,我有一个自定义的身份验证模块。如果页面配置为allow users=“*”或allow users=“?”,我试图在知道用户标识之前退出模块逻辑