【问题标题】:JWTSecurityTokenHandler and SecurityTokenDescriptor not found even though System.IdentityModel.Tokens installed and used即使安装和使用了 System.IdentityModel.Tokens,也找不到 JWTSecurityTokenHandler 和 SecurityTokenDescriptor
【发布时间】:2015-08-02 05:00:56
【问题描述】:

我正在尝试编写一种在 .net C# 中生成 JWT 令牌的方法。通过互联网搜索,我找到了演示如何执行此操作的页面。我关注的一个这样的页面是https://gist.github.com/pmhsfelix/4151369。为了支持这一点,我在包管理器控制台中运行了“Install-Package System.IdentityModel.Tokens.Jwt”,并且可以在我的 paackages.config 中看到“<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.205111437" targetFramework="net45" />"”。但仍然找不到 SecurityTokenDescriptor。我有强烈的感觉是版本不匹配,但我我无法找出它是什么。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: c# .net nuget jwt


    【解决方案1】:

    确保在您的代码中使用:

    using System.IdentityModel.Tokens;
    using Microsoft.IdentityModel;
    

    另外,我相信您需要添加对以下内容的引用:

    System.IdentityModel

    位于 Visual Studio 的“程序集”选项卡中。

    希望对你有所帮助。

    【讨论】:

    • using System.IdentityModel.Tokens; + 添加对System.IdentityModel 的引用应该这样做
    • ^ 只需添加 System.IdentityModel 即可。不需要Microsoft.IdentityModel
    【解决方案2】:

    从 4.x.x 升级到 5.x.x 之后

    改变这一行:

    using System.IdentityModel.Tokens;
    

    收件人:

    using System.IdentityModel.Tokens.Jwt;
    

    【讨论】:

      猜你喜欢
      • 2014-10-26
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 2021-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      相关资源
      最近更新 更多