Johan Pino
Johan Pino

Reputation: 265

How to update a claim in ASP.NET Identity 3.0?

I am working in a asp.net project and i need to update the value of a identity claim.

I read:

How to update a claim in ASP.NET Identity?

I want to do something similar but in Identity 3.0.

Upvotes: 2

Views: 841

Answers (1)

Naeem Sarfraz
Naeem Sarfraz

Reputation: 7430

try something like this?

var identity = new ClaimsIdentity(User.Identity);
identity.RemoveClaim(identity.FindFirst("name"));
identity.AddClaim(new Claim("name", "Jon"));

var authenticationManager = HttpContext.GetOwinContext().Authentication;
authenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant(
    new ClaimsPrincipal(identity),
    new AuthenticationProperties
    {
        IsPersistent = true
    });

Upvotes: 1

Related Questions