I am using Active Directory login in one of my Winforms applications. I get a UserPrincipal
object but I'm not sure how to get the proper accountname from this object? I can see that there is a SamAccountName
that is the same as my account name but it states that this is for old versions of Windows. So how do I get the proper account name no mather old or new Windows systems?
This is the code I use to get the object
if (ADUserName.Length > 0)
context = new PrincipalContext(ContextType.Domain, ADServer, null, ADUserName, ADUserPassword);
else
context = new PrincipalContext(ContextType.Domain, ADServer);
UserPrincipal.FindByIdentity(context, account)