我試圖確定用戶是否是AD組的成員,或者不在AD中。但是,以下似乎並不奏效出於某種原因...return not breaking loop(c#)
public bool MemberOf(string sObjectName, string sGroup, bool bIsGroup)
{
DirectoryEntry dEntry = CreateDirectoryEntry();
DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
if (bIsGroup) dSearcher.Filter = "(distinguishedName=" + sObjectName + ")";
else dSearcher.Filter = "(&(sAMAccountName=" + sObjectName + ")(objectClass=user))";
SearchResult sResult = dSearcher.FindOne();
if (sResult != null)
{
foreach (object oGroup in sResult.Properties["MemberOf"])
{
if (oGroup.ToString() == sGroup) return true;
else this.MemberOf(oGroup.ToString(), sGroup, true);
}
}
return false;
}
另一個變化:http://users.business.uconn.edu/dwick/work/wtf/6-14-2010%201-15-15%20PM.png
也不起作用。這似乎是一個非常愚蠢的問題......但不應該打破「迴歸真實」的循環。
+1 ...很好。 – 2010-06-14 17:25:33