020-29133788
    资 讯
    您的位置:首页 >> 资 讯 >> 软件应用 >> 编程开发 >> 正文
    Asp.Net 查询AD资料 程式

    点击:   发布日期:2013-05-08

    本文来自 www.020fix.com

    [sell=0]
      errormessage.Text = ""

        Try

            Dim ldap_Path = "LDAP://suncolor.com.tw/DC=suncolor, DC=com, DC=tw"

            Dim entry As New DirectoryEntry(ldap_Path, "帐号", "密码", AuthenticationTypes.Secure)

            Dim searcher As New DirectorySearcher("(&(objectCategory=person)(objectClass=user))")

            Dim sResultSet As SearchResult

            Dim strResultSet As String



            searcher.SearchRoot = entry



            searcher.PropertiesToLoad.Add("cn")

            searcher.PropertiesToLoad.Add("sn")

            searcher.PropertiesToLoad.Add("sAMAccountName")

            searcher.PropertiesToLoad.Add("displayname")

            searcher.PropertiesToLoad.Add("userPrincipalName")





            strResultSet = searcher.FindAll().Count.ToString()



            Dim result As SearchResult



            For Each result In searcher.FindAll()

              If Not (result.Properties("cn") Is Nothing) AndAlso Not (result.Properties("sn") Is Nothing) Then

                If searchbox.Text = result.Properties("sAMAccountName")(0).ToString() Then

                    Label1.Text = "帐号:" & (result.Properties("sAMAccountName")(0).ToString())

                    Label2.Text = "显示名称:" & (result.Properties("displayname")(0).ToString())

                    Label3.Text = "姓氏:" & (result.Properties("sn")(0).ToString())

                    Label4.Text = "公用名称:" & (result.Properties("cn")(0).ToString())

                    Label5.Text = "Mail Address:" & (result.Properties("userPrincipalName")(0).ToString())

                End If





              End If

            Next



        Catch ex As Exception

            errormessage.Text = ("There was an error. Error was: " & ex.Message.ToString())



        End Try