0

我收到以下错误

{“指定的域不存在或无法联系。”}

在线

 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
4

1 回答 1

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

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

于 2013-02-10T12:04:49.280 回答