1

我在 VB 中编写了一个代码来访问 LDAP 服务器以进行身份​​验证。但是,它正在引发异常,可能是 nativeObject 调用正在生成异常。动机是对用户进行身份验证。我正在提供代码和异常。请帮我解决这个问题。

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cookie As HttpCookie = New HttpCookie("username")
        cookie.Value = TextBox1.Text
        cookie.Expires = DateAndTime.Now.AddHours(12)
        Response.Cookies.Add(cookie)
        Dim entry As New DirectoryEntry("LDAP://xyz.com/dc=xyz,dc=com", TextBox1.Text, TextBox2.Text)
        Try
            Dim obj As New Object
            obj = entry.NativeObject
            Dim search As New DirectorySearcher(entry)
            search.Filter = "(SAMAccountName=" + TextBox1.Text + ")"
            search.PropertiesToLoad.Add("cn")
            Dim result As SearchResult
            result = search.FindOne()
            If result.Equals(Nothing) then
                MsgBox("Try Again with valid username")
            Else
                MsgBox("User Found!")
            Response.Redirect("~/Dashboard.aspx")
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

我有一个例外

System.Runtime.InteropServices.COMException (0x80005000):未知错误 (0x80005000)

在 System.DirectoryServices.DirectoryEntry.Bind(布尔 throwIfFail)

在 System.DirectoryServices.DirectoryEntry.Bind()

在 System.DirectoryServices.DirectoryEntry.get_NativeObject()

在 _Default.Button1_Click

请为我提供解决方案/根据要求修改代码。

4

1 回答 1

1

DirectoryEntry 中缺少服务器名称

代替

Dim entry As New DirectoryEntry("LDAP://xyz.com/dc=xyz,dc=com", TextBox1.Text, TextBox2.Text)

它应该是

Dim entry As New DirectoryEntry("LDAP://SERVER-NAME/xyz.com/dc=xyz,dc=com", TextBox1.Text, TextBox2.Text)
于 2012-12-07T05:52:55.700 回答