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

maloriopoliumAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.