How do I get the first name and last name of the logged in Windows user?

前端 未结 6 1033
独厮守ぢ
独厮守ぢ 2020-12-04 15:53

How I can get my first name last name with c# in my system (logging in windows with Active Directory username and pass)?

Is it possible to do that without going to t

6条回答
  •  时光说笑
    2020-12-04 16:06

    Had the same issue. After some research and browsing the Microsoft Docs, I found the solution.

    First install the System.DirectoryServices.AccountManagement package using Nuget Package Manager.

    Then while calling the GetUserNameWithoutDomain method pass the following as the parameters:

    GetUserNameWithoutDomain(UserPrincipal.Current.GivenName, UserPrincipal.Current.Surname); This should definitely work!

提交回复
热议问题