473,396 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.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
0 4139

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

Similar topics

4
by: ASGMikeG | last post by:
Hi, How do I find the user object for the current user in Active Directory i.e. the user running my program ? Regards Michael
0
by: Andrew Connell | last post by:
I have a case where I need to be able to query Active Directory to look up a user by their WINNT:\\DOMAIN\USERACCOUNT. The site is authenticating the users (it's a CMS site and they must be...
5
by: Tim::.. | last post by:
Hi can someone please tell me how I change this directory service query so that it searches through each record in the active directory and returns all the accounts! At the moment I can only get...
6
by: Leo_Surf | last post by:
Hello, I need your help adding user in Active Directory from ASP.net website. Could any one provide me the complete code for the html page. As this is my curriculam project and I dont have any...
3
by: Luis Esteban Valencia | last post by:
Hello gusys, Is it possible to make my asp.net application add users to the AD , I also want to be able to delete users, modify their information, everything through a website. Thanks for the...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
10
by: Hriday | last post by:
Hi there, Please help me..It is urgent This is Hriday, working on windows authentication with Active Directory... My requirment is when a user sends a request to my web Applicatoin I want to...
0
by: jakobsgaard | last post by:
It is possible to Map a certificate to a Active Directory User Account from DotNet? Please provide an example. Best regards, Ejnar Jakobsgaard...
2
by: HamishC | last post by:
Hi all, I have been knocking my head against this one for a few days -- haven't been able to find a solution to this anywhere so hopefully someone can help. Situation: A really simple LDAP that...
3
by: =?Utf-8?B?YXppZWdsZXI=?= | last post by:
Hello, everybody. I'd like to do this: For a big program (a web service) I need information about the usergroups an active-directory-user is member of. To be more precise, I need to know if a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.