I'm building a C# application, and I want to identify users by their username. For example, if I logged onto the domain mydomain as the user myusername I'd want to get the mydomain\myusername so I can identify the user.
How can I do this with C#?
I'm building a C# application, and I want to identify users by their username. For example, if I logged onto the domain mydomain as the user myusername I'd want to get the mydomain\myusername so I can identify the user.
How can I do this with C#?
It's very simple indeed:
Environment.UserName
From the MSDN page:
The UserName property provides part of the credentials associated with computer domain names, as returned by the UserDomainName property. This information is typically represented as DOMAIN\username.
This property can be used to identify the current user to the system and application for security or access purposes. It can also be used to customize a particular application for each user.
You can also get the domain name using Environment.UserDomainName
.
try User.Identity.Name or Environment.UserName.
EDIT:
Environment.UserDomainName - Domain
Environment.UserName - UserName