get a null exception with a variable in a list of claims

  • Thread starter Thread starter kstMan
  • Start date Start date
K

kstMan

Guest
Hello, I have the code below where I create a list of claims and add some values:

string email = id_token.GetValue("unique_name").ToString();
string name = id_token.GetValue("given_name").ToString();
DataSet ds;

List<Claim> claims = new List<Claim>()
{
new Claim(ClaimTypes.Name, name),
new Claim(ClaimTypes.Email, email)
};

string roles = "select name from Roles_Table";
ds =
GetDataSet(roles);

if (ds.Tables.Count > 0)
{
foreach (var row in ds.Tables(0).Rows)
claims.
Add(new Claim(ClaimTypes.Role, row("name")));
}


When I want to use it like this:

ClaimsPrincipal cp = ClaimsPrincipal.Current;
var email = cp.FindFirst(ClaimTypes.Email).Value


It says email is null and I don't know why. I also tried :

var email =cp.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value;

But got the same issue. However, the other values of the list are not null. Need help please.

Continue reading...
 
Back
Top