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

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

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

18条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 10:18

    If you are in a network of users, then the username will be different:

    Environment.UserName
    - Will Display format : 'Username'
    

    rather than

    System.Security.Principal.WindowsIdentity.GetCurrent().Name
    - Will Display format : 'NetworkName\Username'
    

    Choose the format you want.

提交回复
热议问题