How do I get the current username in .NET using C#?

后端 未结 18 1727
忘了有多久
忘了有多久 2020-11-22 09:59

How do I get the current username in .NET using C#?

18条回答
  •  执笔经年
    2020-11-22 10:19

    Just in case someone is looking for user Display Name as opposed to User Name, like me.

    Here's the treat :

    System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName

    Add Reference to System.DirectoryServices.AccountManagement in your project.

提交回复
热议问题