Again! Help! I can't connect to Active Directory!

  • Thread starter Thread starter Anna Koloskova
  • Start date Start date
A

Anna Koloskova

Hi,
I'm referring to the question of Amadelle (13 october 2004), please
see

http://groups.google.com/[email protected]&rnum=1

kindly answered by Jared, specifically to the words
---------------------------------------------------------------------
"If you are able to bind, but when you try to view/retrieve the
properties, I
have found that when you try to perform operations asynchronously you
receive the comexception."
---------------------------------------------------------------------
I am trying to do directory search asynchronously in ASP.Net
application, e.g. using begininvoke to call the function that uses
DirectorySearcher. I am getting COM exception "The specified domain
either does not exist or could not be contacted".
The same code called not from async call works ok.
Can you shed any light on this behavior? Im completely lost.
Thank you
Anna
 
You should bind using explicit credentials when using this from asp.net.

1. Supply explicit credentials
dirEntry = new DirectoryEntry("LDAP://......",
"account@domain", "pwd", AuthenticationTypes.Secure));

2. Use the above dirEntry object in DirectorySearcher overload in your
asynchronous delegate procedure.
DirectorySearcher mySearcher = new DirectorySearcher(dirEntr, ...);

You have to make sure both DirectoryEntry and DirectorySearcher are using
the same connection. If you don't pay attention to this you will end with
two connections using different credentials. The reason for this is that
both run on separate threads, in your case, one is impersonating while the
other runs with the default process identity, with as result two different
connections with different access tokens.

Willy.
 
Willy, thanks a milliion for this!
The new thread was indeed working under local ASPNET account.
Explicit login and password in DirectoryEntry object did not work for me,
but I've passed System.Security.Principal.WindowsIdentity.GetCurrent() from
the calling process and impersonated it before doing directory search.
Thanks again
Anna
 
Back
Top