c# adsi errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rubble

    c# adsi errors

    Hello, Im trying to see if a user exists in active directory. The
    code I have has been posted elsewhere and apparantly works for
    others....but it will not work for me. I get the error: "The
    specified domain either does not exist or could not be contacted."
    Can anyone please help me? Im completely lost here.

    Here is the code (roughly the same code works when I create it in
    vbs):

    string LDAPPath = "LDAP://DC=mydomain,DC= mydc,DC=mydc2,D C=mydc3,DC=com" ;

    DirectoryEntry de = new DirectoryEntry( );

    de.Path = LDAPPath.ToStri ng();

    DirectorySearch er searcher = new DirectorySearch er();

    searcher.Search Root = de;

    searcher.Filter = "(name=clfield) ";

    searcher.PageSi ze = 10;

    searcher.Search Scope = SearchScope.Sub tree;

    searcher.Proper tiesToLoad.Add( "name");

    searcher.Proper tiesToLoad.Add( "userAccountCon trol");

    SearchResultCol lection results = searcher.FindAl l();
    string szTest = "";

    foreach(SearchR esult result in results)

    {

    szTest = result.Properti es["name"][0].ToString();

    }


    Thanks - B. Rubble
  • Marc Scheuner [MVP ADSI]

    #2
    Re: c# adsi errors

    >Hello, Im trying to see if a user exists in active directory. The[color=blue]
    >code I have has been posted elsewhere and apparantly works for
    >others....bu t it will not work for me. I get the error: "The
    >specified domain either does not exist or could not be contacted."[/color]

    Does your domain REALLY consist of all of these FIVE elements??
    [color=blue]
    >string LDAPPath = "LDAP://DC=mydomain,DC= mydc,DC=mydc2,D C=mydc3,DC=com" ;[/color]

    Try downloading my ADSI Browser from http://www.lupus.ch/adsi (bottom
    of the page) - it shows you your AD hierarchy - go to your domain -
    what does the AD path for that domain look like?? Usually, there's at
    most 3 dc= elements - five is very unusual.

    Also, I'd probably rather just try and bind to the user in question,
    rather than doing a directory search....
    [color=blue]
    >string LDAPPath = "LDAP://DC=mydomain,DC= mydc,DC=mydc2,D C=mydc3,DC=com" ;
    >DirectoryEnt ry de = new DirectoryEntry( );
    >de.Path = LDAPPath.ToStri ng();[/color]

    ????? LDAPPath already *IS* a string - why do a .ToString() on a
    string??

    I'd prefer:

    DirectoryEntry de = new DirectoryEntry( LDAPPath); - that's it

    Or better yet - if you know your user is called "John Doe", and lives
    in the "Users" container of your domain, just bind to:

    DirectoryEntry deUserInQuestio n = new DirectoryEntry( "LDAP://cn=John
    Doe,cn=Users,dc =fabrikam,dc=co m");

    if(deUserInQues tion != null)
    // user exists
    else
    // user doesn't exist

    Marc

    =============== =============== =============== =============== ====
    Marc Scheuner May The Source Be With You!
    Bern, Switzerland m.scheuner(at)i nova.ch

    Comment

    • Marc Scheuner [MVP ADSI]

      #3
      Re: c# adsi errors

      >Hello, Im trying to see if a user exists in active directory.

      Or better yet - use the static method "Exists" to test for a user's
      existence, given its LDAP path (from MSDN):

      -------------------------------------------------------
      You can use the Exists method if you would like to verify an entry is
      in the directory. This method is provided in the DirectoryEntry class.
      The following code example shows how to use Exists.

      if (DirectoryEntry .Exists("LDAP://CN=John
      Doe,CN=Users,DC =fabrikam,DC=co m"))
      Console.WriteLi ne("object exists");
      else
      Console.WriteLi ne("object does not exist");

      Marc
      =============== =============== =============== =============== ====
      Marc Scheuner May The Source Be With You!
      Bern, Switzerland m.scheuner(at)i nova.ch

      Comment

      • Rubble

        #4
        Re: c# adsi errors

        Thanks! These replies are excellent info.

        I have a follow up though if someone would happen to have the
        expertise....

        I implemented the suggestions above...noticed I got the same error, so
        I converted the project to a console app and it worked great. I then
        realized that I cant access AD stuff through my asp.net code.

        The old way -- I would compile the code into a dll and put it in COM+
        and run it under an account that had rights to browse AD.

        How do I do this with .net and C#???

        Thanks again for the great suggestions!
        B. Rubble.

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: c# adsi errors

          See inline ****

          Willy.

          "Rubble" <rahkim@hotmail .com> wrote in message news:8adeed.031 1190552.450b6a1 @posting.google .com...[color=blue]
          > Thanks! These replies are excellent info.
          >
          > I have a follow up though if someone would happen to have the
          > expertise....
          >
          > I implemented the suggestions above...noticed I got the same error, so
          > I converted the project to a console app and it worked great. I then
          > realized that I cant access AD stuff through my asp.net code.
          >[/color]

          **** Specify valid credentials in the Username and Password properties of your DirectoryEntry object de.
          de.Username = "domain\\Domain AccountWithADAc cessPrivileges"
          de.Password = "hisPasswor d"

          [color=blue]
          > The old way -- I would compile the code into a dll and put it in COM+
          > and run it under an account that had rights to browse AD.
          >
          > How do I do this with .net and C#???
          >[/color]
          **** Use the ".NET Framework Services Installation Utility" regsvcs.exe to register your correctly implemented .NET assembly with
          the COM+ catalog.
          [color=blue]
          > Thanks again for the great suggestions!
          > B. Rubble.[/color]


          Comment

          • Rubble

            #6
            Re: c# adsi errors

            This looks like the way to go:[color=blue]
            > **** Use the ".NET Framework Services Installation Utility" regsvcs.exe to register your correctly implemented .NET assembly with
            > the COM+ catalog.[/color]

            Because I cant pass a password over the net.


            Thanks! I appreciate the advice!

            B. Rubble.

            "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message news:<#oMlyZsrD HA.2432@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
            > See inline ****
            >
            > Willy.
            >
            > "Rubble" <rahkim@hotmail .com> wrote in message news:8adeed.031 1190552.450b6a1 @posting.google .com...[color=green]
            > > Thanks! These replies are excellent info.
            > >
            > > I have a follow up though if someone would happen to have the
            > > expertise....
            > >
            > > I implemented the suggestions above...noticed I got the same error, so
            > > I converted the project to a console app and it worked great. I then
            > > realized that I cant access AD stuff through my asp.net code.
            > >[/color]
            >
            > **** Specify valid credentials in the Username and Password properties of your DirectoryEntry object de.
            > de.Username = "domain\\Domain AccountWithADAc cessPrivileges"
            > de.Password = "hisPasswor d"
            >
            >[color=green]
            > > The old way -- I would compile the code into a dll and put it in COM+
            > > and run it under an account that had rights to browse AD.
            > >
            > > How do I do this with .net and C#???
            > >[/color]
            > **** Use the ".NET Framework Services Installation Utility" regsvcs.exe to register your correctly implemented .NET assembly with
            > the COM+ catalog.
            >[color=green]
            > > Thanks again for the great suggestions!
            > > B. Rubble.[/color][/color]

            Comment

            Working...