By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,201 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,201 IT Pros & Developers. It's quick & easy.

c# adsi errors

P: n/a
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,DC=mydc3,DC=com";

DirectoryEntry de = new DirectoryEntry();

de.Path = LDAPPath.ToString();

DirectorySearcher searcher = new DirectorySearcher();

searcher.SearchRoot = de;

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

searcher.PageSize = 10;

searcher.SearchScope = SearchScope.Subtree;

searcher.PropertiesToLoad.Add("name");

searcher.PropertiesToLoad.Add("userAccountControl" );

SearchResultCollection results = searcher.FindAll();
string szTest = "";

foreach(SearchResult result in results)

{

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

}
Thanks - B. Rubble
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
>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."
Does your domain REALLY consist of all of these FIVE elements??
string LDAPPath = "LDAP://DC=mydomain,DC=mydc,DC=mydc2,DC=mydc3,DC=com";
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....
string LDAPPath = "LDAP://DC=mydomain,DC=mydc,DC=mydc2,DC=mydc3,DC=com";
DirectoryEntry de = new DirectoryEntry();
de.Path = LDAPPath.ToString();


????? 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 deUserInQuestion = new DirectoryEntry("LDAP://cn=John
Doe,cn=Users,dc=fabrikam,dc=com");

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

Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Nov 15 '05 #2

P: n/a
>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=com"))
Console.WriteLine("object exists");
else
Console.WriteLine("object does not exist");

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Nov 15 '05 #3

P: n/a
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.
Nov 15 '05 #4

P: n/a
See inline ****

Willy.

"Rubble" <ra****@hotmail.com> wrote in message news:8a***********************@posting.google.com. ..
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.

**** Specify valid credentials in the Username and Password properties of your DirectoryEntry object de.
de.Username = "domain\\DomainAccountWithADAccessPrivileges"
de.Password = "hisPassword"

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#???
**** Use the ".NET Framework Services Installation Utility" regsvcs.exe to register your correctly implemented .NET assembly with
the COM+ catalog.
Thanks again for the great suggestions!
B. Rubble.

Nov 15 '05 #5

P: n/a
This looks like the way to go:
**** Use the ".NET Framework Services Installation Utility" regsvcs.exe to register your correctly implemented .NET assembly with
the COM+ catalog.
Because I cant pass a password over the net.
Thanks! I appreciate the advice!

B. Rubble.

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message news:<#o**************@TK2MSFTNGP10.phx.gbl>... See inline ****

Willy.

"Rubble" <ra****@hotmail.com> wrote in message news:8a***********************@posting.google.com. ..
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.


**** Specify valid credentials in the Username and Password properties of your DirectoryEntry object de.
de.Username = "domain\\DomainAccountWithADAccessPrivileges"
de.Password = "hisPassword"

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#???

**** Use the ".NET Framework Services Installation Utility" regsvcs.exe to register your correctly implemented .NET assembly with
the COM+ catalog.
Thanks again for the great suggestions!
B. Rubble.

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.