LDAP身份验证指定的域不存在或无法联系

时间:2013-02-10 11:53:51

标签: asp.net vb.net exception com ldap

我收到以下错误

  

{“指定的域名不存在或不存在   接触。 “}

 Dim adResults = adSearch.FindOne.Path

任何人都可以建议为什么会这样吗?看到下面的代码

Dim ID As FormsIdentity = DirectCast(User.Identity, FormsIdentity)
    Dim ticket As FormsAuthenticationTicket = ID.Ticket
    Dim adTicketID As String = ticket.Name
    Dim adSearch As New DirectorySearcher
    adSearch.Filter = ("(userPrincipalName=" & adTicketID & ")")
    Dim adResults = adSearch.FindOne.Path
    Dim adResultsDirectory As New DirectoryEntry(adResults)
    Dim found As Boolean = False
    For Each entry In adResultsDirectory.Properties("memberOf")
        Response.Write(entry)
        Response.Write("<br/>")
        If entry = "CN=GroupName,CN=UserGroup,DC=my,DC=domain,DC=com" Then
            found = True
        End If

    Next
    If Not (found) Then
        Response.Redirect("login.aspx")
    End If

1 个答案:

答案 0 :(得分:0)

您的域名在哪里指定? DirectoryEntry的第一个参数应该是您的AD服务器,如下所示:LDAP://adserver

以下是我用于检查用户是否在AD中进行身份验证的代码:

Dim dsDirectoryEntry As New DirectoryEntry("LDAP://" & domain, userName, password)

Dim dsSearch As New DirectorySearcher(dsDirectoryEntry)
Dim dsResults As SearchResult = dsSearch.FindOne()

If dsResults IsNot Nothing Then
    Return True
Else
    Return False
End If

我正在从配置中读取域名,用户名和密码来自登录表单输入。