Here is some sample code:
var ctx = new PrincipalContext(ContextType.Domain);
var up1 = AuthenticablePrincipal.FindByIdentity(ctx, IdentityType.Sid, "S-1-5-21-.......");
var up2 = AuthenticablePrincipal.FindByIdentity(ctx, IdentityType.UserPrincipalName, "login@contoso.com");
If the user is in the same domain where this code is executing, it finds the user in both cases. If the user is in another, two-way trusted forest, both return null.
When I create a domain-local group on the current domain and put users from other forests in it, and I list the members of the group with GroupPrincipal.GetMembers
, it does find and it does resolve the foreign objects as well. So this task is certainly possible and our infrastructure is also working fine.
How to find a user from another forest with UserPrincipal.FindByIdentity
? Or with any other method that uses PrincipalContext
?