如何在ASP.NET Identity 3.0中更新声明?

时间:2016-06-21 11:26:58

标签: asp.net asp.net-identity claims-based-identity

我在asp.net项目中工作,我需要更新身份声明的价值。

我看了:

How to update a claim in ASP.NET Identity?

我想在Identity 3.0中做类似的事情。

1 个答案:

答案 0 :(得分:1)

尝试这样的事情?

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
    });