首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LDAP服务器不是操作错误仅发生在Windows 10上

问LDAP服务器不是操作错误仅发生在Windows 10上
EN

Stack Overflow用户
提问于 2016-05-17 11:35:18
回答 1查看 915关注 0票数 0

我一直在使用这个函数来查找用户的用户名电子邮件地址(我的所有用户都在同一个域名上),没有问题,但是现在一些用户已经升级到Windows 10,我收到了一个错误:

服务器无法操作。

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

代码语言:javascript
复制
    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的地方,代码工作得很好。

有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2016-05-19 12:19:50

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

您可以使用域名DNS名称:

代码语言:javascript
复制
Dim entry As New DirectoryServices.DirectoryEntry("LDAP://domain.com")

或域名的可分辨名称:

代码语言:javascript
复制
Dim entry As New DirectoryServices.DirectoryEntry("LDAP://DC=domain,DC=com")

看看这有什么区别。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37274981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档