我有一个在RegisterGlobalFilters()
中注册的自定义IAuthenticationFilter实现。在我的项目中,我目睹了以下调用序列:IAuthenticationFilter.OnAuthenticationChallenge()的用途是什么
- IAuthenticationFilter.OnAuthentication
- 授权(如果有的话)
- 控制器动作
- IAuthenticationFilter.OnAuthenticationChallenge
它为什么会发生后控制器的动作?从this blog post我读
要记住的是,
OnAuthenticationChallenge
不 所有其他行动过滤器之前一定运行最关键的事情。它可以在 的各个阶段运行。
如果我们无法确定它何时被调用,它有什么用处?
您提到的博客文章还说:“OnAuthenticationChallenge方法在OnAuthentication方法后运行,您可以使用OnAuthenticationChallenge方法对请求执行其他任务。”基本上,如果你想修改你的Action结果,你可以在“OnAuthenticationChallenge”方法上实现它。 – DmitryK