加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

.net – IAuthenticationFilter.OnAuthenticationChallenge()的

发布时间:2020-12-15 21:03:28 所属栏目:asp.Net 来源:网络整理
导读:我在RegisterGlobalFilters()中注册了自定义 IAuthenticationFilter实现.在我的项目中,我正在目睹以下呼叫序列: IAuthenticationFilter.OnAuthentication 授权(如果有的话) 控制器动作 IAuthenticationFilter.OnAuthenticationChallenge 为什么在控制器动作
我在RegisterGlobalFilters()中注册了自定义 IAuthenticationFilter实现.在我的项目中,我正在目睹以下呼叫序列:

> IAuthenticationFilter.OnAuthentication
>授权(如果有的话)
>控制器动作
> IAuthenticationFilter.OnAuthenticationChallenge

为什么在控制器动作之后会发生?从this blog post开始,我读到了

The key thing to remember is that OnAuthenticationChallenge does not
necessarily run before every other Action Filter. It can run at
various stages.

如果我们无法判断它究竟何时被调用,它怎么有用呢?

解决方法

Source

“只要请求失败了操作方法的身份验证或授权策略,MVC框架就会调用OnAuthenticationChallange方法.OnAuthenticationChallenge方法传递一个AuthenticationChallengeContext对象,该对象派生自ControllerContext类”

所以,一个实际的例子是:

1 – 您设置自定义授权过滤器

2 – 用户在授权方法上失败

调用3 – OnAuthenticationChallenge方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读