need help in Active Directory Connection

Last post 10-23-2007 12:18 PM by evildave. 7 replies.

Sort Posts:

  • need help in Active Directory Connection

    10-03-2007, 11:22 AM
    • Loading...
    • blast
    • Joined on 09-12-2007, 3:18 PM
    • Posts 12

    Hi All,

    I'm trying to connect active directory to asp.net web application made in C# using Visual Web Developer.I'm not sure whether i'm going on the righ track, since its my new research on Active directory connection, please check my code. i'm trying to establish connection to active directory and get the user details.....please recorrect me if i'm wrong.. The code i used to connect to the LDAP is ass below(it says bad url......)

     DirectoryEntry rootEntry = new DirectoryEntry();
                rootEntry .Path ="ldap://000.000.000.00:000/CN=Users,OU=Role-Based,OU=North America,DC=ca,DC=com";
                rootEntry .Username ="DN=CN=GetPaid,OU=Role-Based,OU=North America,DC=ca,DC=com";
                rootEntry.Password ="aaaaaaaa";
               
                DirectorySearcher search = new DirectorySearcher(rootEntry);
               search .SearchRoot =rootEntry ;
                string username="abcdef";
                //searcher .Filter ="(&(objectClass=user) (cn=" + UserName +"))";
                search.Filter = "(SAMAccountName=" + username + ")";
                search.PropertiesToLoad.Add("cn");
                SearchResult result = search.FindOne();
                if(result ==null)
                    Response.Write("false");
                else
                    Response.Write("true");

  • Re: need help in Active Directory Connection

    10-03-2007, 11:34 AM
    • Loading...
    • ruek23
    • Joined on 09-03-2007, 3:01 PM
    • UK
    • Posts 26
    Andy Morrell
    Bsc Computer Science
    .NET Developer

    =============================================
    Please Mark the helpful post(s) as Answered
  • Re: need help in Active Directory Connection

    10-03-2007, 1:42 PM
    • Loading...
    • blast
    • Joined on 09-12-2007, 3:18 PM
    • Posts 12

    thanks for your quick reply .....i tried inserting the 141.202.551.21:389  but still it says

    Exception Details: System.Runtime.InteropServices.COMException: Unknown error (0x80005000)

    Source Error:

    Line 73:             search.Filter = ("SAMAccountName=" + "gansa04 ");
    Line 74:             search.PropertiesToLoad.Add("cn");
    Line 75:             SearchResult result = search.FindOne();
    Line 76:             Response.Write(result.ToString());
    Line 77:             //String strValue=result.Properties("cn")
    ....please help.is the rest of the coding right?

     

     

  • Re: need help in Active Directory Connection

    10-03-2007, 5:14 PM
    • Loading...
    • ruek23
    • Joined on 09-03-2007, 3:01 PM
    • UK
    • Posts 26

    I'm sorry I don't have much experience with C# and LDAP I just know about LDAP connection strings.

    Sorry

    Andy 

    Andy Morrell
    Bsc Computer Science
    .NET Developer

    =============================================
    Please Mark the helpful post(s) as Answered
  • Re: need help in Active Directory Connection

    10-04-2007, 9:08 AM
    • Loading...
    • blast
    • Joined on 09-12-2007, 3:18 PM
    • Posts 12

    Can anyone else help me.......thanks!

  • Re: need help in Active Directory Connection

    10-15-2007, 9:19 AM
    • Loading...
    • johram
    • Joined on 06-13-2006, 10:36 AM
    • Sweden
    • Posts 3,352
    • Moderator

    Your username must be in the form <domain>\<username> when you specify it with a DirectoryEntry.

    If this post was useful to you, please mark it as answer. Thank you!
  • Re: need help in Active Directory Connection

    10-22-2007, 7:55 AM
    • Loading...
    • stevedale
    • Joined on 08-14-2007, 9:22 AM
    • Denmark
    • Posts 105

    Have you tried LDAP:\\ rather than ldap:\\?

  • Re: need help in Active Directory Connection

    10-23-2007, 12:18 PM
    • Loading...
    • evildave
    • Joined on 10-23-2007, 12:15 PM
    • Posts 2

    Try changing this line

     search.Filter = "(sAMAccountName=gansa04)";

     

    That is how I set my search filter and it works..

     Dave Doeppel

Page 1 of 1 (8 items)
Microsoft Communities
Page view counter