473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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,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
5 2627
>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
>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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Miguel Orrego | last post by:
Hi, I have found some code that authenticates users agains a domain using ADSI. I then redirect to another page and pass the username they have entered as a string. However, it would be nice to...
4
by: Akhlaq Khan | last post by:
we are developing an intranet application (web based) which needs to detect the logged in user ID of the user hitting the website. the intranet is huge and based on win2k active directory (around...
2
by: Christopher Johannsen | last post by:
Good Day: I am working on building a tool Using ASP/COM & IIS5.1 for a non-administrative technical support team to change domain passwords for users. I have the basic interface built and...
1
by: Ryan Ritten | last post by:
I was wondering if anyone knew how (or if it's even possible) to cache the results of an ADSI call in asp for a longer period of time. Basically what I am doing is I have a website that loads the...
14
by: Arran Pearce | last post by:
Hi, I am looking for a way to use System.DirectoryServices to find all users on a domain whos accounts are either locked out or disabled. I have used ADSIEdit and the mmc schema add-in to try...
3
by: Roy Osherove | last post by:
Hi folks. I have an ASP.Net application that runs a .Net dll that uses WMI and ADSI(both managed) to connect to a given IIS root and search through it. When not using the ASP.Net client, but...
3
by: chat_devil | last post by:
hi, does anyone know if it is possible to remove an attribute that can not be read into the ADSI property cache/collection. i'm trying to do an eDirectory password change from .net directory...
1
by: zmunoz | last post by:
I am working on a script using ADSI via COM in PHP. The script works for the most part when I query a user using the following function: function passwordExpires($userDN) { $comLDAP = new...
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.