0

I am making an application where the authentication to that is bind to Azure Active Directory.

I need to get the first name and last name of logged in user. Currently I am able to get username by using

public string name
{
    get
    {
        return HttpContext.Current.User.Identity.Name;
    }
}

It returns me "Subham.kumar@nathcorp.com", but I don't need the whole username.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
subham
  • 164
  • 1
  • 14

1 Answers1

0

You can use Claims

        foreach (Claim cl in ((ClaimsIdentity)(User.Identity)).Claims)
        {
            switch (cl.Type)
            {
                case ClaimTypes.Email:
                    currentUser.Mail = cl.Value;
                    break;
                case ClaimTypes.Name:
                case ClaimTypes.Surname:
                    currentUser.Name = cl.Value;
                    break;
                case ClaimTypes.GivenName:
                    currentUser.FirstName = cl.Value;
                    break;
             }
         }
User.Anonymous
  • 1,719
  • 1
  • 28
  • 51