Usually a Windows NON domain user does not have a UPN name. As below If I run WHOAMI with / upn:
C:\>WHOAMI /UPN ERROR: Unable to get User Principal Name (UPN) as the current logged-on user is not a domain user.
Based on this, using the code below, we can determine whether the user is a domain user or not.
var upnName = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName; if (upnName == null) {
Another long way would be to get a SAM username. Then, using DirectoryEntry, DirectorySearcher and other AD APIs, iterate through the entire federated domain of the machine and find if the user is in any of the domain that we iterate.
Find all machine domains ex1 and ex2
Here's how to get domain user information from Active Directory in C #
source share