views:

183

answers:

2

Can you elaborate what goes behind the scene when we create DirectoryEntry instance?

Code snippet:

DirectoryEntry dirEntry = new DirectoryEntry("LDAP://CN=jsmith,DC=fabrikam,DC=Com", userName, password);

I mean, how authentication works? Who talks with whom? Assume the code above is in a console application.

A: 

From what I can see using Reflector, it uses the activds.dll

For example:

[DllImport("activeds.dll", EntryPoint="ADsOpenObject", CharSet=CharSet.Unicode, ExactSpelling=true)]
private static extern int IntADsOpenObject(string path, string userName, string password, int flags, [In, Out] ref Guid iid, [MarshalAs(UnmanagedType.Interface)] out object ppObject);

http://msdn.microsoft.com/en-us/library/aa772238(VS.85).aspx

Kevin
A: 

Creating the DirectoryEntry doesn't do much more than actually creating the object in memory. The DirectoryEntry object is actually just a managed wrapper around the basic IADsObject of the unmanaged, COM-based ADSI (Active Directory Service Interfaces) interface to Active Directory (which you could - if you really wanted to - use directly, too).

Only when you start using its properties, or when you access the underlying .NativeObject COM object, will it actually connect to Active Directory, log on with your current credentials (or any alternate credentials you supplied), and try and fetch the information for that DirectoryEntry from AD.

Marc

marc_s