0

当我们创建 DirectoryEntry 实例时,您能详细说明幕后发生的事情吗?

代码片段:

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

我的意思是,身份验证如何工作?谁和谁说话?假设上面的代码在控制台应用程序中。

4

2 回答 2

1

创建DirectoryEntry对象并没有比实际在内存中创建对象更多。该DirectoryEntry对象实际上只是一个托管包装器,它围绕IADsObject非托管、基于 COM 的ADSI (Active Directory Service Interfaces)Active Directory 接口(如果您真的想的话,您也可以直接使用)。

只有当您开始使用其属性或访问底层.NativeObjectCOM 对象时,它才会真正连接到 Active Directory,使用您当前的凭据(或您提供的任何备用凭据)登录,并尝试从中获取该 DirectoryEntry 的信息广告。

马克

于 2009-07-16T12:28:48.567 回答
0

从我可以看到使用反射器,它使用 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

于 2009-07-16T11:58:46.907 回答