• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 899
  • Last Modified:

Active Directory LDAP query not working

Hi,

I have 2 Domains. Domain A and Domain B connected via a 2 way Trust. I'm trying to perform an LDAP query in .NET to the Active Directory from one Domain to the other Domain.

The Active Directory sits in Domain B. I've logged in from my PC which sits in Domain A started up Visual Studio and created a ConsoleApp in C#. My code is below.

Every time it executes the FindOne() method, it throws a "Logon failure: unknown user name or bad password" error.

I am extremely frustrated why this is not working because I can't seem to query an Active Directory in Domain B from Domain A.

I have already asked our Network Admin to create a service account in Domain B.

Can somebody please help? I am stumped!!!

DirectoryEntry dEntry = new DirectoryEntry("LDAP://OU=Users,OU=ABC,DC=XXX,DC=YYY,DC=local", "XXX.YYY.local\\serviceAccount", "password");
            DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
            dSearcher.Filter = "(SAMAccountName=firstname.lastname)";
            SearchResult result = dSearcher.FindOne();

Open in new window

0
maloriopolium
Asked:
maloriopolium
1 Solution
 
maloriopoliumAuthor Commented:
Also, just some more info,

I have downloaded an LDAP browser called Softerra LDAP Administrator 2010.1
I can successfully log in as the service Account and traverse through the hierarchy in Domain B's Active Directory whilst logged into my PC under my Domain A's Windows Account.
So why won't my query work in .NET? Is .Net unable to query across 2 domains?
0
 
ViebsCommented:
Ask your Network Admin to add the LDAP account to the Domain Admins group in order to eliminate any rights issues.
0
 
msmamjiCommented:
try this and see if it works.
DirectoryEntry dEntry = new DirectoryEntry("LDAP://OU=Users,OU=ABC,DC=XXX,DC=YYY,DC=local"); 
	   dEntry.Username = "XXX.YYY.local\\serviceAccount";
	   dEntry.Password = "password";
            DirectorySearcher dSearcher = new DirectorySearcher(dEntry); 
            dSearcher.Filter = "(SAMAccountName=firstname.lastname)"; 
            SearchResult result = dSearcher.FindOne();

Open in new window

0
 
PFoeckelerCommented:
Hi,

you try to authenticate with this credential:

"XXX.YYY.local\\serviceAccount"

That seems to be invalid for a windows authentication. It has to be

"serviceAccount@XXX.YYY.local"    _OR_      "XXX\serviceAccount"

where "XXX" ist the netbios name of your domain (the one which is shown in the "domain" field when you log on to the domain with ctrl-alt-del

Philipp
0
 
maloriopoliumAuthor Commented:
Hi guys,

Thanks for the replies,

msmamji:I have tried your suggestion, but it still doesn't work. I still get the same error as before.

PFoeckeler: I have also tried your suggestion but it also doesn't work. I still get the same error as before.

What I ended up doing, was actually using the lower level namespace System.DirectoryServices.Protocols which seem to have worked.

Not sure why the LdapConnection class found in System.DirectoryServices.Protocols works but the DirectoryEntry class found in System.DirectoryServices doesn't work. Anyone have any ideas about this?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Tackle projects and never again get stuck behind a technical roadblock.
Join Now