AD connection works in windows app, but not in asp.net

mconnolly

New member
Joined
Mar 26, 2003
Messages
2
Location
London
Hi there,

This is probably down to something childishly simple that Im missing...

Im trying to get user information out of active directory. The code works perfectly well in a windows application running on my machine, but when I try to run it from asp.net I get the following error:
"The specified domain either does not exist or could not be contacted"

Code:
Dim root As New DirectoryEntry("LDAP://DC=domain1,DC=domain2,DC=com", "myusername", "mypassword")
Dim searcher As New DirectorySearcher(root)
With searcher
   .PropertiesToLoad.Add("cn")
   .PropertiesToLoad.Add("mail")
   .PropertiesToLoad.Add("givenName")
   .PropertiesToLoad.Add("sn")
   .PropertiesToLoad.Add("userPrincipalName")
   .Filter = "(&(objectClass=user))"
End With
Dim queryresults As SearchResultCollection = searcher.FindAll()
Dim result As SearchResult
Dim s As String
For Each result In queryresults
   If Not result.Properties("givenName") Is Nothing Then
      s = result.Properties("givenName")(0)
      s += " "
   End If
   If Not result.Properties("sn") Is Nothing Then
      s += result.Properties("sn")(0)
   End If
   If Not result.Properties("userPrincipalName") Is Nothing Then
      mylist.Items.Add(s)
   End If
Next
Can anyone tell me what Im doing wrong?:confused:
 
Last edited by a moderator:
Back
Top