Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, July 22, 2010 11:34 AM
Hi, I'm new to using Active directory and ASP.Net in general, and was hoping someone with more experience could help me out.
I have a textbox which a user would type in a name and there is a listbox that is populated by the results of the directorySearcher.
This works fine when debugging, but on our test server i recieve the error:
The specified domain either does not exist or could not be contacted.
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.
Exception Details: System.Runtime.InteropServices.COMException: The specified domain either does not exist or could not be contacted.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
Here is my code:
lstNames.Items.Clear()
Dim nameArr(2) As String
Dim first As String
Dim last As String
Dim filter As String
Dim count As Integer = 0
nameArr = txtName.Text.Split(CChar(" "))
first = nameArr(0)
If nameArr.Length = 1 Then
filter = "(&(objectCategory=person)(objectClass=user)(givenName=" + first + "))"
Else
last = nameArr(1)
filter = "(&(objectCategory=person)(objectClass=user)(givenName=" + first + ")(sn=" + last + "))"
End If
Dim search As DirectorySearcher = New DirectorySearcher(filter)
For Each result As SearchResult In search.FindAll
Dim entry As DirectoryEntry = result.GetDirectoryEntry()
foundNames(0, count) = CStr(entry.Properties("givenName").Value)
foundNames(1, count) = CStr(entry.Properties("sn").Value)
foundNames(2, count) = CStr(entry.Properties("mail").Value)
foundNames(3, count) = CStr(entry.Properties("telephonenumber").Value)
lstNames.Items.Add(foundNames(0, count) + " " + foundNames(1, count))
count = count + 1
Next
Any help would be greatly appreciated.
Tom
All replies (1)
Thursday, July 22, 2010 4:31 PM âś…Answered
If you want to search for users in a domain, you should provide the path for the domain like in my example below
Dim de As DirectoryEntry = new DirectoryEntry("LDAP://company.com:389/dc=company,dc=com")
Dim search As DirectorySearcher = New DirectorySearcher(de)
search.Filter = filter
More examples and info about DirectorySearcher can be obtained on MSDN.