I am trying to get members of this active directory group using the DirectoryServices.AccouneManagement namespaces classes in C #.
If I have a main constructor of context objects specified for a specific domain, then whenever I access a member from a group located in other domains, I run the following error: "The referral was returned from the server."
Scenario: I have different subdomains in the root domain For example: emea.mycorp.com, asia.mycorp.com, asiapacific.mycorp.com, xyz.mycorp.com
If I run the code below from the domain xyz.mycorp.com, for a group in asiapacific If I specify the server name in the main context object, I could access the group.
private PrincipalContext context = new PrincipalContext(ContextType.Domain, "asiapacific domain server name");
If there are users from other domains in my group, such as emea \ abcd, the code below does not work in UserPrincipal:
GroupPrincipal SearchGroup = GroupPrincipal.FindByIdentity(context, "Dev Team"); GroupName = new List<string>(); foreach (UserPrincipal p in SearchGroup.GetMembers()) { GroupName.Add(p.SamAccountName + " " + p.DistinguishedName + " " + p.Name); }
So, is there a way to pass the context for the root domain so that the code works regardless of the domain to which the user belongs. I tried below and with no one was lucky:
private PrincipalContext context = new PrincipalContext(ContextType.Domain, "mycorp.com");
or
private PrincipalContext context = new PrincipalContext(ContextType.Domain, "DC=mycorp,DC=com");