【问题标题】:LDAP The server is not operational error occurs on Windows 10 OnlyLDAP 服务器无法运行错误仅在 Windows 10 上发生
【发布时间】:2016-05-17 11:35:18
【问题描述】:

我一直在使用此功能从用户名中查找用户电子邮件地址(我的所有用户都在同一个域中)没有问题,但现在一些用户已升级到 Windows 10,我收到错误消息:

服务器无法运行

我已经参考这个问题和答案对我的代码进行了更改,所以现在我选择了默认命名上下文,但错误仍然存​​在: System.DirectoryServices - The server is not operational

    Public Function UserEmail(ByRef Username As String) As String
        UserEmail = ""
        Dim deRoot As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")

        If Not deRoot Is DBNull.Value Then
            Dim defaultNamingContext As String = deRoot.Properties("defaultNamingContext").Value.ToString()
            Dim path As String
            path = "LDAP://" & defaultNamingContext


            Dim entry As New DirectoryServices.DirectoryEntry(Path)
            Dim search As New DirectoryServices.DirectorySearcher(entry)

            search.Filter = "(&(objectClass=user)(anr=" + Username + "))"
            search.PropertiesToLoad.Add("mail")

            Dim result As DirectoryServices.SearchResult
            result = search.FindOne

            If IsDBNull(result) Then
                UserEmail = ""
            Else
                UserEmail = result.Properties("mail")(0)
            End If

        End If

    Return UserEmail
End Function

代码在我的用户使用 Windows 7 和 8 时运行良好。

有什么建议吗?

【问题讨论】:

  • 这段代码是否在每个用户的机器上运行?
  • 是的,它在 Windows 7 和 8 中运行良好,但在 Windows 10 中出错。它将电子邮件发送给另一个用户,该用户名已保存在数据库中。
  • 这些 Windows 10 机器是否与 Windows 7/8 机器加入了同一个域?
  • 哪一行抛出异常?
  • 它们都在同一个域中,并且行 dim deRoot as New DirectoryServices 抛出异常。

标签: vb.net active-directory ldap


【解决方案1】:

我不知道为什么它会在 LDAP://RootDSE 崩溃。但是如果你只有一个域,你可以硬编码域名而不是使用 RootDSE。

您可以使用任一域 DNS 名称:

Dim entry As New DirectoryServices.DirectoryEntry("LDAP://domain.com")

或域名专有名称:

Dim entry As New DirectoryServices.DirectoryEntry("LDAP://DC=domain,DC=com")

看看这有什么不同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 2016-08-13
    • 2019-10-07
    相关资源
    最近更新 更多