locked
Checking if user is valid in Active Directory RRS feed

  • Question

  • User-1260059516 posted

    Hi there I have tried every thing to solve my problem but yet no luck, so please if any one could help, please do...

    I am trying to read the given name of login users from active directory using asp.net 2.0..

    First the structure of my active directory is

    ***.***.col/Staff/College Staff/Individuals

    all users are stored in the net domain.

    All users are stored in the group individuals.

    The coding below when read only return false.. this code I am using first only checks if the user exists.

    //=========== FUNCTION TO CONNECT TO AD =====
    Public Shared Function GetDirectoryEntry() As DirectoryEntry

    Dim de As DirectoryEntry = New DirectoryEntry()
    de.Path = "LDAP://net"

    Return de

    End Function

    //==============

    ===============Function to check if user exist =====

    Public Function UserExists(ByVal UserName As String) As Boolean

    Dim de As DirectoryEntry = GetDirectoryEntry()

    Dim deSearch As DirectorySearcher = New DirectorySearcher()

    'deSearch.SearchRoot = de
    deSearch.SearchScope = SearchScope.Subtree

    deSearch.Filter = "(&(objectCategory=Person)(objectClass=user))"

    Dim results As SearchResultCollection = deSearch.FindAll

    If results.Count = 0 Then

    Return False

    Else

    Return True

    End If

    End Function
    ===================================================

    The above code returs FALSE, WHEN A VALID USER NAME IS PROVIDED.

    Any help please.

    Thursday, January 26, 2006 3:55 PM

All replies

  • User1354132231 posted
    Try this post and convert to VB.NET if necessary.
    Thursday, February 2, 2006 12:51 PM
  • User-1260059516 posted

    Hi there, cheers for your reply, I have tried your c# example but it keeps giving me user not found,

    My users details are stored in the following OU {Individuals}, thius is located within other OUs.

    Basically My system admin did not use the Users OU but created his own, our Active Directory is structures as followed

     

    Staff / College Staff / Individuals

    The connection string I am using for LDAP is string adPath = "LDAP://net/OU=Individuals,OU=College Staff, OU=Staff,DC=Mydomain,DC=com";

    where am I going wrong? please help I have being trying to do thjis since June 05.

    Cheers in advance.

    Friday, February 3, 2006 6:10 PM
  • User-1260059516 posted

    Hi dunnry, firts I must say cheers for your reply, and second sorry for PMijg you, but thi probelm I have being trying to solved since mid  05,

    I have tried your c# example but it keeps giving me user not found,

    My users details are stored in the following OU {Individuals}, thius is located within other OUs.

    Basically My system admin did not use the Users OU but created his own, our Active Directory is structures as followed

     

    Staff / College Staff / Individuals

    The connection string I am using for LDAP is string adPath = "LDAP://net/OU=Individuals,OU=College Staff, OU=Staff,DC=Mydomain,DC=com";

    where am I going wrong? please help I have being trying to do thjis since June 05.

    Cheers in advance.

    Wednesday, February 8, 2006 11:22 AM
  • User1354132231 posted
    What is the type of LDAP directory that you are using?  If you are using ADAM or 3rd Party, the code needs to be modified.  That particular example would only have worked with AD.

    Wednesday, February 8, 2006 2:53 PM
  • User-1260059516 posted

    The LDAP I am using is Active Directory (IIS  Windows server 2003).

    No problem connecting just unable to read properties of users.

    Conrad

    Saturday, February 11, 2006 5:35 AM
  • User1354132231 posted
    So, are you unable to read properties, or actually find the user.  If you can't find the user, I would suspect that they are located somewhere other than where you think they are in the directory.

    You can do this a couple ways to troubleshoot.  I would use ldp.exe and test to make sure that it is not something other than the code:

    1. Launch ldp.exe (ships with ADAM and with Windows Admin Pak)
    2. Connection > Connect and enter servername or domain name if AD and port (389 is default port).  You should see some general information scroll telling you that you have a valid connection
    3. CTRL-B to bind.  Bind as currently logged on user if possible.  If you are in another domain or not joined to domain, enter your credentials explicitly and use Advanced (Negotiate).  If successful you will see message in pane to right.
    4. CTRL-S to search. From dropdown list, select your default partition - don't worry about the OU at this point.  Make sure subtree is selected for scope and enter "(&(objectClass=user)(objectCategory=person))" for filter and search.  You should see all your user objects.  If you dont'... well you dont' have any!

    What do you get when you try this?
    Tuesday, February 14, 2006 11:25 AM