本文介绍了C#和Active Directory:测试OU是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用C#创建Active Directory之前,如何测试Active Directory中是否存在组织单位?
How can i Test if and Organizational Unit Exists in Active Directory before creating it with C# ?
推荐答案有一个<$您可以使用 DirectoryEntry 上的c $ c> .Exists()方法-假设您具有正确 LDAP OU的路径!
There's a .Exists() method on the DirectoryEntry which you can use - assuming you have the correct LDAP path for your OU!
if (DirectoryEntry.Exists("LDAP://" + objectPath)) { // ...... }您的主要问题是是:您使用的路径是错误-用户是通用容器,因此需要解决像这样:
Your main problem will be: the path you're using is wrong - the Users is a generic container and thus needs to be addressed like this:
LDAP://192.168.0.1/CN=Users请注意 CN = 前缀。如果您有实际的组织单位,则必须在其前面加上 OU =
Note the CN= prefix. If you had an actual organizational unit, it would have to be prefixed with OU=
查看方法:(几乎)所有内容活动目录
更多推荐
C#和Active Directory:测试OU是否存在
发布评论