【发布时间】:2013-05-29 09:36:39
【问题描述】:
是否有任何直接的方法可以让所有 OU 进入 Active Directory? 我试过下面的代码,我在
处得到 Com Exception (Invalid operation)ouSearch.FindAll()
我的代码如下所示。
public static List<string> GetAllOus(string ldapServer, string ldapUserName, string ldapPassWord)
{
List<string> orgUnits = new List<string>();
string defaultNamingContext;
DirectoryEntry rootDSE = new DirectoryEntry(ldapServer + "/dc=server-dc,dc=com", ldapUserName, ldapPassWord, AuthenticationTypes.Anonymous);
//defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();
//DirectoryEntry defaultentry = new DirectoryEntry("LDAP://" + defaultNamingContext);
DirectorySearcher ouSearch = new DirectorySearcher(rootDSE,
"(objectClass=organizational-Unit)",
null, SearchScope.Subtree);
foreach (SearchResult resEnt in ouSearch.FindAll())
{
string OUName = resEnt.GetDirectoryEntry().Name;
orgUnits.Add(OUName);
}
return orgUnits;
}
请帮我解决这个问题。
提前致谢
【问题讨论】:
-
你的
ldapServer有什么价值?? -
@marc_s:它包含像 LDAP://192.168.2.5(AD 服务器)这样的值
-
好的,只要绝对确保
LDAP://部分是大写的(不要使用ldap://或Ldap://或类似的东西......)跨度> -
我认为你应该使用 (objectClass=organizationalUnit) 而不是 (objectClass=organizational-Unit)。
-
ya.. 完全大写。
标签: c# asp.net active-directory ou