c# - Update user info in View Identity -
i have extension class includes method this:
public static string getname(this iprincipal user) { if (user.identity.isauthenticated) { claimsidentity claimsidentity = user.identity claimsidentity; foreach (var claim in claimsidentity.claims) { if (claim.type == "name") { return claim.value; } } return ""; } else return ""; }
after call action update user table include name
, name called @user.getname()
not update although column in database has change.
if user logout system , login again, name display in view changed last update.
i have solution logout , login again after class action update user info. there other solutions without logout?
when user logout , login again, authentication cookie regenerated latest change , user see latest update. can update authentication cookie authenticationresponsegrant
method:
var identity = (claimsidentity)user.identity; identity.removeclaim(identity.findfirst("name")); identity.addclaim(new claim("name", value)); iowincontext context = request.getowincontext(); var authenticationcontext = await context.authentication.authenticateasync(defaultauthenticationtypes.applicationcookie); if (authenticationcontext != null) authenticationmanager.authenticationresponsegrant = new authenticationresponsegrant(new claimsprincipal(identity), new authenticationproperties { ispersistent = true });
Comments
Post a Comment