1

我的 DBA 告诉我,我的一个应用程序确实使我们的一个 LDAP 服务器陷入困境。我已经多次查看代码,但我看不到任何方法来限制我必须点击 LDAP 的次数。所以现在我决定看看我实际获取数据的方式,看看是否有更好的方法。我没有开发我正在使用的实际数据模型,我不确定 System.DirectoryServices.Protocols 库的全部内容。

如果更熟悉使用 .NET LDAP 提供程序的人能给我一些建议,我将不胜感激。这是我用来在我们的 LDAP 服务器中查找条目的函数:

    <DirectoryServicesPermission(SecurityAction.LinkDemand, Unrestricted:=True)> _
    Public Overloads Shared Function GetSearchResultEntry(ByVal connection As LdapConnection, ByVal searchDirectoryPath As String, ByVal filter As String, _
                                          ByVal attributes As String(), ByVal scope As Protocols.SearchScope) As SearchResultEntry

        If connection Is Nothing Then
            Throw New ArgumentNullException("connection", "An ldap connection must be provided in order to search for a directory.")
        End If

        If Strings.IsNullOrBlank(searchDirectoryPath) Then
            Throw New ArgumentException("A directory path must be provided in order to search for a directory.", "searchDirectoryPath")
        End If

        If Strings.IsNullOrBlank(filter) Then
            Throw New ArgumentException("A search filter must be provided in order to search for a directory.", "filter")
        End If

        Dim resp As SearchResponse = CType(connection.SendRequest(New SearchRequest(searchDirectoryPath, filter, scope, attributes)), SearchResponse)

        If resp.Entries.Count > 0 Then
            Return resp.Entries(0)
        End If

        Return Nothing

    End Function

.NET LDAP 提供程序是否可能有点慢?如果有人有一些关于他们如何在他们的商店中使用 LDAP 的代码示例,那就太好了。

无论如何,提前感谢您的帮助。

谢谢,
厘米

4

1 回答 1

1

两件事情:

  1. 您只关心 1 个条目。该代码看起来会返回特定查询的所有结果。您可以尝试寻找单一结果查询样式。
  2. 如果做不到这一点,我怀疑你可以做很多事情来让这个特定的代码在服务器上更容易。您可能会看到是否有某种方法可以减少调用此函数的频率——也许是通过缓存结果。
于 2008-12-08T22:48:39.990 回答