I've been working on this problem for about a week and nearly drove me crazy.
I have two domain ("Domain A") that contains a group ("COUNTRY-CN") and I want to add users from the trusted domain ("Domain B") to the group ("COUNTRY-CN") . I can manually add the users to the group without any problem,using Active Directory Users and Computers.
I can use the code to add user to the group in the same domain. But when I tried to add user to trusted domain,
the error showed: The server is unwilling to process the request. (Exception from HRESULT: 0x80072035)
the code:
DirectoryEntry oGroup = new DirectoryEntry(@"LDAP://CN=COUNTRY-CN,OU=ByCountry,OU=Groups,OU=Standard,DC=A,DC=com
", @"A\lei", "XXXXXX"); // AuthenticationTypes.Secure);}
DirectoryEntry oUser = GetDirectoryEntryByAccount(UserName, DomainReference, "");
string strDomain = "B.com";
String UserPath = "LDAP://" + strDomain + "/<SID=" + sid + ">";
if (oGroup != null && oUser != null )
{
oGroup.Invoke("Add", new Object[] { UserPath }); //the error messge stopped at this line
oGroup.CommitChanges();
return true;
}
// UserPath LDAP://B.com/<SID=S-1-5-21-3913676305-412022068-3582600154-1180>
// oGroup
LDAP://CN=COUNTRY-CN,OU=ByCountry,OU=Groups,OU=Standard,DC=A,DC=com
Could anyone help to look at it ? thanks much. Lei