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

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

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

18条回答
  •  庸人自扰
    2020-11-22 10:08

    The documentation for Environment.UserName seems to be a bit conflicting:

    Environment.UserName Property

    On the same page it says:

    Gets the user name of the person who is currently logged on to the Windows operating system.

    AND

    displays the user name of the person who started the current thread

    If you test Environment.UserName using RunAs, it will give you the RunAs user account name, not the user originally logged on to Windows.

提交回复
热议问题