Query Active Directory for User ID

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • justintaitt
    New Member
    • Jun 2007
    • 11

    Query Active Directory for User ID

    Hi,
    I am new to active directory and am trying to query it for the user name and ID of members of a group to populate a drop down list in the form: firstname lastname (userID)
    When I run the page which calls this function through visual studio it works fine and the drop down list is populated. However when I run the page over the intranet I get this error.

    Unknown error (0x8000500c)
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Unknown error (0x8000500c)
    Exception Details: System.Runtime. InteropServices .COMException:

    Source Error:

    Line 152: userProps = gpMemberEntry.P roperties

    Line 154: obVal = userProps("Give nName").Value & " " & userProps("sn") .Value & " (" & userProps("sAMA ccountName").Va lue & ")"

    with this code:
    Dim _path As String = "LDAP://WI.FCIB.COM/DC=WI, DC=FCIB, DC=COM"
    Dim groupMembers As New StringCollectio n


    ' Try
    Dim ent As New DirectoryEntry( _path)
    Dim srch As New DirectorySearch er("(" & strGroup & ")")
    Dim coll As SearchResultCol lection

    'Get the results
    coll = srch.FindAll()

    Dim rs As SearchResult

    'Get the information for each member found
    For Each rs In coll

    Dim resultPropColl As ResultPropertyC ollection
    Dim memberColl As Object

    resultPropColl = rs.Properties

    For Each memberColl In resultPropColl( "member")

    Dim gpMemberEntry As New DirectoryEntry( "LDAP://WI.FCIB.COM/" & memberColl.ToSt ring)
    Dim userProps As PropertyCollect ion
    Dim obVal As Object

    userProps = gpMemberEntry.P roperties

    obVal = userProps("Give nName").Value & " " & userProps("sn") .Value & " (" & userProps("sAMA ccountName").Va lue & ")"

    If Not obVal Is Nothing Then
    groupMembers.Ad d(obVal.ToStrin g)
    End If

    Next

    Next

    Return groupMembers

    'Catch ex As Exception
    ' Return Nothing
    'End Try

    For some quick debugging I tried:
    Dim _path As String = "LDAP://WI.FCIB.COM/DC=WI, DC=FCIB, DC=COM"
    Dim groupMembers As New StringCollectio n


    ' Try
    Dim ent As New DirectoryEntry( _path)
    Dim srch As New DirectorySearch er("(" & strGroup & ")")
    Dim coll As SearchResultCol lection

    'Get the results
    coll = srch.FindAll()

    Dim rs As SearchResult

    'Get the information for each member found
    For Each rs In coll

    Dim resultPropColl As ResultPropertyC ollection
    Dim memberColl As Object

    resultPropColl = rs.Properties

    For Each memberColl In resultPropColl( "member")

    Dim gpMemberEntry As New DirectoryEntry( "LDAP://WI.FCIB.COM/" & memberColl.ToSt ring)
    Dim userProps As PropertyCollect ion
    Dim obVal As Object

    userProps = gpMemberEntry.P roperties

    My.Response.Wri te("< br/>" & userProps("Give nName").Value)
    My.Response.Wri te(" " & userProps("sn") .Value)
    My.Response.Wri te(" " & userProps("sAMA ccountName").Va lue)
    'obVal = userProps("Give nName").Value & " " & userProps("sn") .Value & " (" & userProps("SAMA ccountName").Va lue & ")"

    'If Not obVal Is Nothing Then
    ' groupMembers.Ad d(obVal.ToStrin g)
    'End If

    Next

    Next

    Return groupMembers

    'Catch ex As Exception
    ' Return Nothing
    'End Try

    Which gave me the same error except it was for the line:
    My.Response.Wri te(" " & userProps("sAMA ccountName").Va lue)

    Does this then mean that I can't load this attribute? And if so, how can I get around it because I must get the userIDs from AD

    Thanks for the help.
Working...