How do I get the current username in .NET using C#?
如何使用C#在.NET中获取当前用户名?
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
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 : 'NetworkNameUsername'
Choose the format you want.
尝试属性: Environment.UserName
。
上一篇: 什么是.NET程序集?
下一篇: 如何使用C#在.NET中获取当前用户名?