2
为什么会为什么GroupPrincipal.FindByIdentity即使在我知道该组存在时也会返回null?
GroupPrincipal group = GroupPrincipal.FindByIdentity(getPrincipalContext(),
"TEST_DESTINATION_GRP");
回报null
?我知道TEST_DESTINATION_GRP
存在于组织单位下。
我的代码:
private void addUserToGroup(string userName, string groupName)
{
try
{
UserPrincipal user = UserPrincipal.FindByIdentity(getPrincipalContext(), IdentityType.SamAccountName, "jcolon");
GroupPrincipal group = GroupPrincipal.FindByIdentity(getPrincipalContext(), "TEST_DESTINATION_GRP");
//just to show that I can access AD
ArrayList x = getUserGroups(userName);
foreach (var xy in x)
{
Console.WriteLine(xy);
}//I can access AD FINE
if (group == null)
{ Console.WriteLine("Wtf!"); }
Console.WriteLine(user);
Console.WriteLine(group + "empty why!!!!");
}
catch (Exception e)
{
//log e
}
}
private PrincipalContext getPrincipalContext()
{
PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain,sDefaultOU);
return oPrincipalContext;
}
上述代码的输出是:
Domain Users GRP_ADMIN_SERVER GRP_PROG_III CTXXA-FlexUser CTXXA-Users Wtf Abanico, [email protected] empty why!!!!
有什么想法?