How can i get the DomainName\AccountName with the .NET Framework?

Environment.UserDomainName contains the domain/computer name that your account is joined to. Environment.UserName contains only the username. To get the result you're after, you need to concaternate the variables(Environment.UserDomainName & "\\" & Environment.UserName). This only works well in a local context though, if you use this code in a website, you'll get the account name that your application pool is running under. In asp.net, use HttpContext.Current.User.Identity.Name instead.


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

You can use the Environment.UserDomainName property to retrieve the domain and Environment.UserName to retrieve the user name:

Dim domainAndUserName As String _
    = Environment.UserDomainName & "\\" & Environment.UserName