dotnet get logged in user code example Example: c# get username string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;