【问题标题】:What goes behind the scene when we create System.DirectoryServices.DirectoryEntry instance?当我们创建 System.DirectoryServices.DirectoryEntry 实例时,幕后发生了什么?
【发布时间】:2009-07-16 11:43:30
【问题描述】:

您能否详细说明我们创建 DirectoryEntry 实例时的幕后情况?

代码sn-p:

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

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

【问题讨论】:

    标签: c# active-directory windows-authentication


    【解决方案1】:

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

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

    马克

    【讨论】:

      【解决方案2】:

      从我使用 Reflector 可以看到,它使用了 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

      【讨论】:

        猜你喜欢
        • 2013-04-18
        • 2015-09-16
        • 2019-03-22
        • 1970-01-01
        • 1970-01-01
        • 2010-11-22
        • 2022-11-16
        • 1970-01-01
        • 2016-07-09
        相关资源
        最近更新 更多