0

我正在运行一个测试活动目录并尝试使用 ldap 进行查询。我创建了一个可分辨名称为空的 searchrequest 对象和一个过滤器,它抛出 noSuchObject 错误代码和“对象不存在”消息。我只是从我的测试广告中得到这个,如果我使用我公司的生产广告,我没有得到异常,只是没有命中的响应。我需要在我的测试广告中进行哪些更改才能看到类似的行为?

4

3 回答 3

0

@marc_s 通过给你一种搜索方式来回答

回到你的问题,只是回忆一下:

LDAP 搜索是

  1. 您要求开始搜索的点头(在您的情况下是您的 OU 的 DN)
  2. 搜索范围(基础、单级、子树)
  3. 您的搜索过滤器 ((objectClass=group))
  4. 您要检索的属性

在您的情况下,当您的 ADSI 层能够找到默认域时,它就可以工作。所以我认为你必须创建一个真正的 LDAP-SEARCH 请求,也许还需要提供凭据。

于 2011-07-06T15:44:54.223 回答
0

您可以使用 aPrincipalSearcher和“按示例查询”主体进行搜索:

// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// define a "query-by-example" principal - here, we search for a UserPrincipal 
// and with specified last name (surname)
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.Surname = "Willis";

// create your principal searcher passing in the QBE principal    
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

// find all matches
foreach(var found in srch.FindAll())
{
    // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
}

如果您还没有 - 绝对阅读 MSDN 文章Managing Directory Security Principals in the .NET Framework 3.5,它很好地展示了如何充分利用System.DirectoryServices.AccountManagement

当然,根据您的需要,您可能希望在您创建的“示例查询”用户主体上指定其他属性:

  • Surname(或姓氏)
  • DisplayName(通常:名字 + 空格 + 姓氏)
  • SAM Account Name- 您的 Windows/AD 帐户名称
  • User Principal Name- 您的“username@yourcompany.com”样式名称

您可以在 上指定任何属性UserPrincipal并将其用作PrincipalSearcher.

于 2011-07-06T04:50:49.923 回答
0

感谢其他答案。我通过在连接中使用 GC 端口 3268 而不是 DC 端口 389 解决了我的问题。

于 2011-07-06T20:31:19.413 回答