Add claims on successful login and retrieve it elsewhere in the application

前端 未结 5 1940
借酒劲吻你
借酒劲吻你 2020-12-14 01:51

Please I need assistance in implementing a custom way of assigning claims to authenticated users. On successful login,

var result = await SignInManager.Pass         


        
5条回答
  •  无人及你
    2020-12-14 02:03

    The Claim property from IdentityUser gives you an ICollection with that collection you can call the following C# method:

        public string GetCustomClaimValue(ICollection claimCollection, string customClaimType)
        {
            string claimValue = "";
            foreach (IdentityUserClaim claim in claimCollection)
            {
                if (claim.ClaimType == customClaimType)
                {
                    claimValue = claim.ClaimValue;
                    break;
                }
            }
            return claimValue;
        }
    

提交回复
热议问题