C# 即使已安装并使用System.IdentityModel.Tokens,也未找到JWTSecurityTokenHandler和SecurityTokenDescriptor

C# 即使已安装并使用System.IdentityModel.Tokens,也未找到JWTSecurityTokenHandler和SecurityTokenDescriptor,c#,.net,nuget,jwt,C#,.net,Nuget,Jwt,我正在尝试编写一个方法来在.NETC#中生成JWT令牌。在互联网上搜索时,我找到了演示如何做到这一点的页面。我下面的一页就是。为了支持这一点,我在Package manager控制台中运行了“Install Package System.IdentityModel.Tokens.Jwt”,并可以在我的papackages.config中看到“””。但仍然找不到SecurityTokenDescriptor。我有一种强烈的感觉,这是一些版本不匹配,但我无法找到它是什么。有人能帮我解决这个问题吗?请

我正在尝试编写一个方法来在.NETC#中生成JWT令牌。在互联网上搜索时,我找到了演示如何做到这一点的页面。我下面的一页就是。为了支持这一点,我在Package manager控制台中运行了“
Install Package System.IdentityModel.Tokens.Jwt
”,并可以在我的papackages.config中看到“
”。但仍然找不到SecurityTokenDescriptor。我有一种强烈的感觉,这是一些版本不匹配,但我无法找到它是什么。有人能帮我解决这个问题吗?

请确保在代码中使用:

using System.IdentityModel.Tokens;
using Microsoft.IdentityModel;
此外,我相信您需要添加以下内容:

系统识别模型

可在Visual Studio的“程序集”选项卡中找到


希望这对您有所帮助。

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

更改此行:

using System.IdentityModel.Tokens;
致:


使用System.IdentityModel.Tokens
+添加对
System.IdentityModel
的引用应该可以^只需添加
System.IdentityModel
就可以了。不需要
Microsoft.IdentityModel
using System.IdentityModel.Tokens.Jwt;