我在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 – 您设置自定义授权过滤器