By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,212 Members | 1,096 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,212 IT Pros & Developers. It's quick & easy.

Query Active Directory for User ID

P: 11
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.Properties

Line 154: obVal = userProps("GivenName").Value & " " & userProps("sn").Value & " (" & userProps("sAMAccountName").Value & ")"

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


' Try
Dim ent As New DirectoryEntry(_path)
Dim srch As New DirectorySearcher("(" & strGroup & ")")
Dim coll As SearchResultCollection

'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 ResultPropertyCollection
Dim memberColl As Object

resultPropColl = rs.Properties

For Each memberColl In resultPropColl("member")

Dim gpMemberEntry As New DirectoryEntry("LDAP://WI.FCIB.COM/" & memberColl.ToString)
Dim userProps As PropertyCollection
Dim obVal As Object

userProps = gpMemberEntry.Properties

obVal = userProps("GivenName").Value & " " & userProps("sn").Value & " (" & userProps("sAMAccountName").Value & ")"

If Not obVal Is Nothing Then
groupMembers.Add(obVal.ToString)
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 StringCollection


' Try
Dim ent As New DirectoryEntry(_path)
Dim srch As New DirectorySearcher("(" & strGroup & ")")
Dim coll As SearchResultCollection

'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 ResultPropertyCollection
Dim memberColl As Object

resultPropColl = rs.Properties

For Each memberColl In resultPropColl("member")

Dim gpMemberEntry As New DirectoryEntry("LDAP://WI.FCIB.COM/" & memberColl.ToString)
Dim userProps As PropertyCollection
Dim obVal As Object

userProps = gpMemberEntry.Properties

My.Response.Write("< br/>" & userProps("GivenName").Value)
My.Response.Write(" " & userProps("sn").Value)
My.Response.Write(" " & userProps("sAMAccountName").Value)
'obVal = userProps("GivenName").Value & " " & userProps("sn").Value & " (" & userProps("SAMAccountName").Value & ")"

'If Not obVal Is Nothing Then
' groupMembers.Add(obVal.ToString)
'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.Write(" " & userProps("sAMAccountName").Value)

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.
Jun 29 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.