如何在使用 C# 创建 Active Directory 之前测试组织单元是否存在?
最佳答案
DirectoryEntry
上有一个 .Exists()
方法,您可以使用它 - 假设您的 OU 具有正确 LDAP 路径!
if (DirectoryEntry.Exists("LDAP://" + objectPath))
{
// ......
}
您的主要问题是:您使用的路径错误 - Users
是一个通用容器,因此需要地址是这样的:
LDAP://192.168.0.1/CN=Users
注意 CN=
前缀。如果您有一个实际的组织单位,它必须以 OU=
要获得优质资源,请查看 Howto: (almost) everything in Active Directory
关于C# 和事件目录 : test if an OU exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16767966/