The WindowsIdentity(string) constructor requires the username to be in [email protected] format. But in my case I get the usernames from a DB in the old DOMAIN\user format (and then have to check their Windows role membership).
What is the best way of creating WindowsPrincipal from the old style (sAMAccountName) username?
It does seem that there is no way of converting the username format without involving a query to Active Directory. Since that is the case there is no need to create
WindowsPrincipalfor checking the group membership since that would probably need yet another connection to AD.By using the
System.DirectoryServices.AccountManagementnamespace you can both get the UPN of the user and check the group membership.