您好,我正在研究 JWT 令牌,并尝试使用 Asp .net 核心使用剃刀视图声明角色。为此,我尝试使用以下代码。
@{
var jwtHandler = new JwtSecurityTokenHandler();
var tokenContent = jwtHandler.ReadToken(tokenModel.Result) as JwtSecurityToken;
var role = tokenContent.Claims.First(claim => claim.Type == "Role").Value;
var email = tokenContent.Claims.First(claim => claim.Type == "email").Value;
}
我收到此错误:
the type or namespace name 'jwtsecuritytokenhandler' could not be found
如何使用剃须刀视图声明角色?
您需要在NuGet Packages
中安装System.IdentityModel.Tokens.Jwt
dll。
然后添加命名空间:
using System.IdentityModel.Tokens.Jwt;