gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:25:54 25 4
gpt4 key购买 nike

我有一个自定义 IAuthenticationFilterRegisterGlobalFilters() 中注册的实现.在我的项目中,我目睹了以下调用序列:

  • IAuthenticationFilter.OnAuthentication
  • 授权(如有)
  • Controller Action
  • IAuthenticationFilter.OnAuthenticationChallenge

  • 为什么会在 Controller 操作后发生?来自 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方法被调用。

    关于.net - IAuthenticationFilter.OnAuthenticationChallenge() 的目的是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22223540/

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