.net – IAuthenticationFilter.OnAuthenticationChallenge()的目的是什么

前端之家收集整理的这篇文章主要介绍了.net – 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.

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

@R_301_323@

Source

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

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

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

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

调用3 – OnAuthenticationChallenge方法.

猜你在找的asp.Net相关文章