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

Yves picture Yves · Aug 6, 2009 · Viewed 607.1k times · Source

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

Answer

juan picture juan · Aug 6, 2009
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;