LDAP目录条目在.net - 不工作OU =用户条目、目录、用户、工作

2023-09-04 00:08:37 作者:▁背叛゜全杀无赦

我有以下的code(C#):

I have the following code (C#):

(调整了来自:的http://www.eggheadcafe.com/conversation.aspx?messageid=31766061&threadid=31766050)

DirectorySearcher dseSearcher = new DirectorySearcher();

string rootDSE = dseSearcher.SearchRoot.Path;
DirectoryEntry rootDE = new DirectoryEntry(rootDSE);

string userDSE = rootDSE.Insert(7, "OU=Users,");
DirectoryEntry userDE = new DirectoryEntry(userDSE);

的RootDSE 正确地创建,但是,用户 userDSE 不可用,并抛出没有这样的对象在服务器上异常,如果我尝试使用它。

The rootDSE is created correctly, however, the user userDSE is unusable and throws "There is no such object on the server" exception if I attempt to use it.

在LDAP字符串如下:

The LDAP strings are as follows:

根:LDAP:// DC =公司,DC =本地

Root: LDAP://DC=company,DC=local

网友:LDAP:// OU =用户,DC =公司,DC =本地

User: LDAP://OU=Users,DC=company,DC=local

我在Vista上作为管理员运行,但需要这个工作在XP(管理员)也是如此。

I'm running on Vista as Admin, but need this to work on XP (Admin) as well.

我是新来的LDAP和目录管理,所以我在黑暗中跌跌撞撞在这里。有什么想法吗?同时 - 任何文章链接太多,可以给我一些洞察到它是如何工作将AP preciated

I'm new to LDAP and Directory Management, so I'm stumbling around in the dark here. Any thoughts? Also - any articles to link too that could give me some insight into how it all works would be appreciated.

推荐答案

首先我会尝试作为一个测试是很难code您所需的路径当你创建像这样一个目录条目:

The first thing I would try as a test is to hardcode your desired path when you create a directory entry like so:

DirectoryEntry de = new DirectoryEntry("LDAP://OU=Users,DC=company,DC=local");

这会告诉你,pretty的快,如果这是在Active Directory的实际路径。我不知道你的AD样子,所以我不能告诉你,如果这是一个有效的路径或没有。根据您的Active Directory用户和计算机MMC插件,如果这条道路是正确的,那么你应该有你的根域,然后在根目录下的OU文件夹,名为用户。

This will tell you pretty quick if this is an actual path in your Active Directory. I don't know what your AD looks like so I can't tell you if this is a valid path or not. Under your Active Directory Users and Computers MMC plugin, if this path is correct, then you should have your root domain, and a OU folder under the root called Users.

路径,所以如果你的用户文件夹下的另一个OU关闭根那将是比

Paths are generated backwards in AD, so if your Users folder is under another OU off the root than it would be

DirectoryEntry de = new DirectoryEntry("LDAP://OU=Users,OU=<first OU folder>,DC=company,DC=local");

所以,你的AD架构看起来像:

So your AD schema would look like:

 Root 
 |
 --><first OU folder>
     |
     -->Users

如何在.NET管理Active Directory中的大文章:

A great article on how to manage Active Directory in .NET:

方法文档:做(几乎)通过C#一切都在Active Directory

HowTo: Do (Almost) Everything in Active Directory via C#

您可能还需要研究的System.DirectoryServices中,System.DirectoryServices.ActiveDirectory,和.NET 3.5 Framework提供的System.DirectoryServices.AccountManagement命名空间。我相信System.DirectoryServices中,并ActiveDirctory命名空间是可利用的盯着NET 1.1,和AccountManagement介绍在.NET 3.5中。

You might also want to research the System.DirectoryServices, System.DirectoryServices.ActiveDirectory, and the System.DirectoryServices.AccountManagement namespaces provided in the .Net 3.5 Framework. I believe System.DirectoryServices, and ActiveDirctory namespaces were available staring in .Net 1.1, and AccountManagement was introduced in .Net 3.5.

微软文档 - 很多关于如何使用命名空间良好的联系

附录:

要真正找到在广告的用户,你将要做到以下几点:

To actually find a user in AD you will want to do the following:

 DirectoryEntry de = new DirectoryEntry();
 de.Path = "LDAP://DC=company,DC=local";
 de.AuthenticationType = AuthenticationTypes.Secure;

 DirectorySearcher deSearch = new DirectorySearcher();

 deSearch.SearchRoot = de;
 deSearch.Filter = "(&(objectClass=user) (cn=" + username + "))";

 SearchResult result = deSearch.FindOne();

 if (result != null)
 {
     DirectoryEntry deUser = new DirectoryEntry(result.Path);
     ... do what ever you need to the deUser
     deUser.Close();
 }
 
精彩推荐
图片推荐