none
如何获取Startup Owin类中配置的中间件信息? RRS feed

  • 问题

  • 请教个问题,ASP .NET 中加了Start OWIN类,里面配置了jwt中间件,我怎么从其他地方(如Filter)获取到里面的配置信息(JwtBearerAuthenticationOptions)?

    2018年9月4日 3:53

答案

  • 你好,

    据我所知,我们并不能再filter中获取到jwt的option。

    因为startup的configure方法是在filter之后触发的。

    如果你想获取owin的Authentication的type你可以使用如下方法。

                var re = HttpContext.GetOwinContext().Authentication.GetAuthenticationTypes();
    
    结果:


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年9月11日 9:17
  • 你好,

    你的filter不是FilterConfig类里面add的吗?

    如果不是那应该不会。

    如果是filterconfig配置的,那应该会添进去。


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年9月13日 9:28

全部回复

  • 你好,

    据我所知,我们并不能再filter中获取到jwt的option。

    因为startup的configure方法是在filter之后触发的。

    如果你想获取owin的Authentication的type你可以使用如下方法。

                var re = HttpContext.GetOwinContext().Authentication.GetAuthenticationTypes();
    
    结果:


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年9月11日 9:17
  • 您好,有个地方我不大了解:startup.configure不是只有在项目启动时执行的吗?而我的filter并非全局的,这样的话是startup.configure是比filter先执行的啊?

    不过还是很感谢你告知我Authentication的获取方式!

    2018年9月13日 2:40
  • 你好,

    你的filter不是FilterConfig类里面add的吗?

    如果不是那应该不会。

    如果是filterconfig配置的,那应该会添进去。


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年9月13日 9:28