【问题标题】:NET Directory Services throws Error when quering LDAP server (not AD related)NET 目录服务在查询 LDAP 服务器时抛出错误(与 AD 无关)
【发布时间】:2013-06-06 15:06:06
【问题描述】:

我正在使用 .NET 3.5 并且已经构建了一个成功的 LDAP 查找功能来查询 Sun LDAP 服务器上的用户数据。

但是,有一个特定记录(到目前为止)在查找时失败。

调用 Findone 方法时,我收到“年、月和日参数描述无法表示的日期时间”错误。

现在,特别是使用 LDAP 浏览器查看记录,比如 Softerra,我可以看到该特定记录缺少特定属性(baLastupdate 字段)中的数据。

此字段属于日期/时间类型,所以我知道我收到了一个错误,因为 NULL 字段没有被正确解释为日期/时间字段。

我的问题是:我怎样才能截获此错误,使其不会崩溃,因此如果该字段为空白,我不会崩溃。 我没有在任何地方定义 LDAP 系统将提供哪些字段,也没有定义字段的类型。

我的 LDAP 连接设置如下

Public Class LDAPDirectorySearcher
Private Shared LDAPDirEntry As System.DirectoryServices.DirectoryEntry
Private Shared LDAPDirSearcher As DirectorySearcher

Public Shared Function DirSearcherSetup() As DirectorySearcher
    Try
        LDAPDirEntry = New DirectoryEntry
        LDAPDirEntry.Path = "LDAP://aaaa.bbbbb.ccccc.com/ou=people"
        LDAPDirEntry.Username = "yyyyyyyyyyy"
        LDAPDirEntry.Password = "xxxxxx"
        LDAPDirEntry.AuthenticationType = AuthenticationTypes.FastBind

        LDAPDirSearcher = New DirectorySearcher(LDAPDirEntry)
        LDAPDirSearcher.CacheResults = True

    Catch ex As Exception

    End Try
    Return LDAPDirSearcher

End Function

身份验证或设置没有任何问题(它适用于 +100K 其他记录)但是当这个日期/时间字段中没有数据时,它会以某种方式崩溃。我想克服这个 NULL 字段。

【问题讨论】:

  • 如果属性具有generalizedTime 语法,则符合 LDAP 的服务器不允许使用“null”值。
  • tnxs,我正在尝试查看如何拦截此错误

标签: .net vb.net ldap directoryservices


【解决方案1】:

您可以使用PropertiesToLoad 属性来选择要在搜索中检索的属性。请注意,如果您稍后在 SearchResult 上调用 GetDirectoryEntry 方法,它也可能会在那里崩溃。

您也可以尝试较低级别的System.DirectoryServices.Protocols 命名空间。

【讨论】:

  • 成功了.. 需要更多的工作来启动但功能。 Sub New()LDAPDirSearcher = LDAPDirectorySearcher.DirSearcherSetupLDAPDirSearcher.PropertiesToLoad.Add("C")LDAPDirSearcher.PropertiesToLoad.Add("Mail")LDAPDirSearcher.PropertiesToLoad.Add("givenName")LDAPDirSearcher.PropertiesToLoad.Add("SN")LDAPDirSearcher.PropertiesToLoad.Add("l")End Sub
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
  • 2016-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多