gpt4 book ai didi

c# - Action 过滤器 + AspNetRedisProvider

转载 作者:可可西里 更新时间:2023-11-01 11:43:03 25 4
gpt4 key购买 nike

您好,我目前正在为我目前在 asp.net mvc4 中开发的应用程序实现此提供程序“https://github.com/kylesonaty/AspNetRedisProviders”。然而,事情并不像我最初想象的那样美好。由于提供者是从各自的抽象对应物派生的,我确实想知道 asp.net mvc 中的默认授权过滤器是否仍会委托(delegate)对这些提供者的调用

提前致谢

最佳答案

默认授权过滤器会为您的自定义提供商建立的角色提供一些 Hook 。它不是直接的,而是间接的。例如,您的角色提供者将设置角色,授权属性可用于验证特定角色是否已由配置的角色提供者定义。

 protected virtual bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext == null)
throw new ArgumentNullException("httpContext");
IPrincipal user = httpContext.User;
return user.Identity.IsAuthenticated
&& (this._usersSplit.Length <= 0 ||
Enumerable.Contains<string>((IEnumerable<string>) this._usersSplit, user.Identity.Name, (IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase))
&& (this._rolesSplit.Length <= 0 || Enumerable.Any<string>((IEnumerable<string>)
this._rolesSplit, new Func<string, bool>(user.IsInRole)));
}

*this._rolesSplit, new Func(user.IsInRole)));*

例如,最后一行,这将检查角色对当前用户是否有效,这已由角色提供者设置。

关于c# - Action 过滤器 + AspNetRedisProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20579904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com