虽然安装System.IdentityModel.Tokens JWTSecurityTokenHandler和SecurityTokenDescriptor甚至没有发现并使用

虽然安装System.IdentityModel.Tokens JWTSecurityTokenHandler和SecurityTokenDescriptor甚至没有发现并使用

问题描述:

我试图写来生成.NET C#JWT令牌的方法。通过互联网搜索,我发现演示如何做到这一点的页面。我下面一个这样的网页是 https://gist.github.com/pmhsfelix/4151369 。为了支持这一点,我在包管理器控制台跑安装封装System.IdentityModel.Tokens.Jwt ,可以看到<包ID在我paackages.config =System.IdentityModel.Tokens.Jwt版本=4.0.2.205111437targetFramework =net45/&GT。但尽管如此,该SecurityTokenDescriptor找不到。我有一个强烈的感觉,实在是有些版本不匹配,但我不能找出它是什么。有人可以帮我解决这个问题。

I am trying to write a method to generate JWT token in .net C#. Searching through internet I found pages demonstrating how do do this. One such page I am following is https://gist.github.com/pmhsfelix/4151369. To support this, I ran "Install-Package System.IdentityModel.Tokens.Jwt" in the package manager console and can see "<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.205111437" targetFramework="net45" />" in my paackages.config. But still, the SecurityTokenDescriptor is not found. I have a strong feeling it is some version mismatch but I am not able to find out what is it. Can some one help me fix this?

确认,在你的代码中使用:

Make sure that in your code you use:

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



另外,我相信你将需要添加一个引用:

Also, I believe you will need to add a reference to:

System.IdentityModel

..这是在Visual Studio大会选项卡中找到。

.. which is found in the Assemblies tab in Visual Studio.

希望这可以帮助你。