0

Hello I am working on JWT token and trying to claim role using razor view using Asp .net core. For that I tried to use the following code.

@{ 
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;
}

I am getting this error:

the type or namespace name 'jwtsecuritytokenhandler' could not be found

How can I claim role using razor view?

Abhi Singh
  • 321
  • 3
  • 14
  • check if this answers your question: https://stackoverflow.com/questions/27139068/get-asp-net-identity-current-user-in-view – Jakub Kozera May 19 '20 at 09:50

1 Answers1

0

You need to install System.IdentityModel.Tokens.Jwt dll in the NuGet Packages.

Then add namespace:

using System.IdentityModel.Tokens.Jwt;
LouraQ
  • 6,443
  • 2
  • 6
  • 16