Getting current login from Active Directory using C# code

Simply,

string Name = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;

OR

string Name = System.Environment.UserName  

OR

string Name = Environment.GetEnvironmentVariable("USERNAME");

OR

string Name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

works 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)