简体   繁体   English

C#和Active Directory:测试OU是否存在

[英]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.

相关问题 C#在Active Directory中创建OU - C# Create OU in Active Directory C#Active Directory,登录特定OU - C# Active Directory, Login in a specific OU 尝试从 Active Directory 检索和 OU,然后使用 C# 中的目录条目在 OU 上设置新属性 - Trying to Retrieve and OU from Active Directory, then set new properties on an OU using a Directory Entry in C# 使用具有层次结构的c#从活动目录获取OU列表 - Get OU list from active directory using c# with hierarchy 使用C#在Active Directory中获取用户的父OU - Get parent OU of user in Active Directory using C# 当我们在asp.net c#中的活动目录中创建用户时,如何在活动目录中嵌套OU时,如何给出路径来识别OU? - How to give path to identify OU when we have nested OU's in active directory while creating a user in active directory in asp.net c#? 尝试在Active Directory C#中委派OU的控件时,出现DirectoryServicesCOMException“发生操作错误” - DirectoryServicesCOMException “operations error occurred” when trying to delegate control for OU in Active directory C# c#Active Directory…在根目录下创建OU时很奇怪 - c# Active Directory… weirdness when creating a OU just under the root 如何在 Active Directory C# 中的指定 ou 下面列出 ous(组织单位) - How can I list ous (organizational units) below a specified ou in Active Directory C# 使用 C# 中的 LDAP 检查 Active Directory 中存在的用户列表 - Check list of users exist in Active Directory using LDAP in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM