当我们创建 DirectoryEntry 实例时,您能详细说明幕后发生的事情吗?
代码片段:
var dirEntry = new DirectoryEntry("LDAP://CN=jsmith,DC=fabrikam,DC=Com", userName, password);
我的意思是,身份验证如何工作?谁和谁说话?假设上面的代码在控制台应用程序中。
当我们创建 DirectoryEntry 实例时,您能详细说明幕后发生的事情吗?
代码片段:
var dirEntry = new DirectoryEntry("LDAP://CN=jsmith,DC=fabrikam,DC=Com", userName, password);
我的意思是,身份验证如何工作?谁和谁说话?假设上面的代码在控制台应用程序中。
创建DirectoryEntry
对象并没有比实际在内存中创建对象更多。该DirectoryEntry
对象实际上只是一个托管包装器,它围绕IADsObject
非托管、基于 COM 的ADSI (Active Directory Service Interfaces)
Active Directory 接口(如果您真的想的话,您也可以直接使用)。
只有当您开始使用其属性或访问底层.NativeObject
COM 对象时,它才会真正连接到 Active Directory,使用您当前的凭据(或您提供的任何备用凭据)登录,并尝试从中获取该 DirectoryEntry 的信息广告。
马克
从我可以看到使用反射器,它使用 activds.dll
例如:
[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