locked
AD LDAP Search Without Username and Password, Possible?? RRS feed

  • Question

  • User593052413 posted

    Hi peeps,

    I'm trying to do a LDAP search without username and password but it's never been successful. I've read through threads and sites but no solution can be found. Is there anyone here who can help me with this?

    What I'm trying to do is to retrieve the distribution list from the AD and bind it to the DDL. The following codes works perfectly if I supply username and password.

    Is there a way that I can do it without the need for user to supply any login or password? 

    1    Public Function getDistributionListByName(ByVal strFilterObjClass As String, Optional ByVal strOU As String = Nothing) As DataTable
    2    
    3            Dim strPath As String = Nothing
    4            Dim dtbDistributionList As DataTable
    5    
    6            Dim searchRoot As DirectoryEntry = Nothing
    7            Dim search As DirectorySearcher = Nothing
    8    
    9            Dim result As SearchResult = Nothing
    10           Dim resultCol As SearchResultCollection = Nothing
    11   
    12           Try
    13               If strOU <> "" Then
    14                   strPath = strDomainPath + strOU + "," + strDomainPathDC
    15               Else
    16                   strPath = strDomainPath + strDomainPathDC
    17               End If
    18   
    19               'I don't want to input any username and password. Possible?
    20               searchRoot = New DirectoryEntry(strPath, "myusername", "mypassword")
    21               search = New DirectorySearcher(searchRoot)
    22   
    23               search.Filter = "(&(objectClass=" + strFilterObjClass + ")(!msExchHideFromAddressLists=TRUE))"
    24               search.PropertiesToLoad.Add("name")
    25   
    26               resultCol = search.FindAll()
    27               dtbDistributionList = New DataTable
    28               dtbDistributionList.Columns.Add("IME Distribution List")
    29   
    30               If resultCol IsNot Nothing Then
    31                   Dim c As Integer = 0
    32                   For c = 0 To resultCol.Count - 1
    33                       result = resultCol(c)
    34                       If result.Properties.Contains("name") Then
    35                           dtbDistributionList.Rows.Add(result.Properties("name")(0).ToString)
    36                       End If
    37                   Next
    38               End If
    39   
    40   
    41           Catch ex As Exception
    42               dtbDistributionList = Nothing
    43           Finally
    44               result = Nothing
    45               resultCol = Nothing
    46               search = Nothing
    47               searchRoot = Nothing
    48           End Try
    49           Return dtbDistributionList
    50   
    51       End Function
    

    Help is very very much appreciated. Thanks in advance.

    Monday, December 18, 2006 10:01 PM

All replies

  • User-1348799698 posted

    Typically this is done with a service account.  Check with your network security group to see what they say. 

    you can create a directorysearcher object without using a directoryentry.  Just use the strpath instead.  If your AD is locked down, it will not work. (the user that runs your application, Network Service) probably does not have rights to access AD. If you do windows authentication and do impersonation, it might work.

     --JJ

    Tuesday, December 19, 2006 4:00 PM
  • User593052413 posted

    Hi,

    I've tried impersonation and it works.

    However, if I use a web service to consume, it cannot work.

    So I discard the use of webservices.

    Thanks for your response. [:D]

    Wednesday, December 20, 2006 3:56 AM
  • User1801871119 posted

    hi

    can you post your code which is working will be great help. or if you can guide me to any tutorial you know.

    After whole day of reaserch i am dead. but, looking for hope- i am trying to retrive user information without using userID and Password like email name, lastnem, phone etc.

    Hope to hear from you..

    Tuesday, April 17, 2007 10:26 AM