I am developing a MVC 5 internet application and am using Identity 2.1
.
How can I add a claim
to a user, after the user has logged in, where I knows the username
?
Here is what I have:
public void AddClaimToUser(string userName, string type, string value )
{
var AuthenticationManager = HttpContext.Current.GetOwinContext().Authentication;
var Identity = new ClaimsIdentity(userName);
Identity.AddClaim(new Claim(type, value));
AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(Identity), new AuthenticationProperties { IsPersistent = true });
}
However, after I call this method, and I check the claims for the user, the added claim
is not listed.
Here is the code that I am using to get the claims in a controller:
var identity = (ClaimsIdentity)User.Identity;
IEnumerable<Claim> claims = identity.Claims;
Thanks in advance.