[英]C# and Active Directory : test if an OU exist
在使用C#创建Active Directory之前,如何测试Active Directory中是否存在组织单位?
There's a .Exists()
method on the DirectoryEntry
which you can use - assuming you have the correct LDAP path for your OU! 可以使用DirectoryEntry
上的.Exists()
方法-假定您具有OU的正确 LDAP路径!
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: 您的主要问题将是:您使用的路径错误 - Users
是通用容器 ,因此需要这样处理:
LDAP://192.168.0.1/CN=Users
Note the CN=
prefix. 注意CN=
前缀。 If you had an actual organizational unit, it would have to be prefixed with OU=
如果您有一个实际的组织单位,则必须以OU=
为前缀
For a great resource, check out Howto: (almost) everything in Active Directory 要获取大量资源,请查看方法:(几乎)Active Directory中的所有内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.