2
How I can print all different types of claims
that I created during my Owin Identity authentication?
I’m using @User.Identity.Nome
to be able to print only the name, I can’t access the other keys I created.
Currently, I have the following login class:
if (ad.Autentica(Usuario) == true) // SE AUTENTICAR, FAZ O LOGIN
{
var identity = new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.NameIdentifier, Usuario.Login),
new Claim(ClaimTypes.Name, Usuario.Nome),
new Claim(ClaimTypes.Surname, Usuario.Sobrenome),
new Claim(ClaimTypes.Role, Usuario.Departamento),
}, "SgwCookie");
Request.GetOwinContext().Authentication.SignIn(identity);
if (!String.IsNullOrWhiteSpace(model.returnUrl) || Url.IsLocalUrl(model.returnUrl))
{
return Redirect(model.returnUrl);
}
else
{
return RedirectToAction("Index", "Dashboard");
}
}
there is no way I can print the value of this Claim directly into . cshtml?
– Hudson Medeiros
Yes it is possible, I will put at the end of the answer
– Robson Silva
Can’t get a specific one without foreach? Just like @User.Identity.Name
– Hudson Medeiros
You can use
((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("claimType").value
– Robson Silva
I haven’t been able to print out the contents of the Claim yet. I solved what I wanted by passing the content I want to session variables directly to the login controller... But I guess it’s not the best way
– Hudson Medeiros