object.ReferenceEquals is used to 'match'.
public static void ReplaceClaim(this ClaimsIdentity identity, string type, string value) { identity.TryRemoveClaim(identity.Claims.FirstOrDefault(c => c.Type == type)); identity.AddClaim(new Claim(type, value)); }