How can i get the
DomainName\AccountName
as string with the .NET Framework?
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With