检索广告自定义属性在一个批处理 [英] Retrieve AD Custom Attribute in One Batch

查看:234
本文介绍了检索广告自定义属性在一个批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 System.DirectoryServices.AccountManagement 库和 PrincipalSearcher 类检索自定义属性所有校长从调用返回到的FindAll()

Is it possible to use the System.DirectoryServices.AccountManagement library and the PrincipalSearcher class to retrieve a custom attribute for all Principals returned from the call to FindAll()?

我目前使用的这个例子:<?一HREF =http://msdn.microsoft.com/en-us/library/bb552835%28v=vs.90%29.aspx相对=nofollow> http://msdn.microsoft.com/en-us /library/bb552835%28v=vs.90%29.aspx 。

I'm currently using this example: http://msdn.microsoft.com/en-us/library/bb552835%28v=vs.90%29.aspx.

不过,访问我的自定义属性/属性的时候,它似乎是作出另外一趟AD商店。我想它在最初调用这个属性急切地装载到的FindAll()

However, when accessing my custom property/attribute, it seems to be making an additional trip to the AD store. I would like it to eagerly load this property at the initial call to FindAll().

推荐答案

是的,有可能在初始
调用热切加载的所有主体自定义属性的FindAll()。你只需要指定使用[DirectoryProperty(YOUR_PROP_NAME)]属性描述
你的自定义属性的微软样本。

Yes, it is possible to eagerly load the custom attribute for all principals at the initial call to FindAll(). You only have to specify your custom attributes as described in the Microsoft sample using [DirectoryProperty("YOUR_PROP_NAME")] attribute.

通过访问底层的DirectorySearcher的财产PropertiesToLoad使用UserPrincipal类的GetUnderlyingSearcher()方法,
你可以看到您的自定义属性包含
属性的集合加载英寸您可以检查在调试器中PropertiesToLoad集合。

By accessing the underlying DirectorySearcher's property PropertiesToLoad using the GetUnderlyingSearcher() method of the UserPrincipal class you can see that your custom attribute is included in the collection of properties to load. You can examine the PropertiesToLoad collection in the debugger.

在我的机器集合共包含68属性。

On my machine the collection contains a total of 68 properties.

在这里开始的问题和性能损失。该公司的其他房产
包含在此集合更多的往返到Active Directory是必要的检索它们在

And here begins the problem and the performance penalty. The more properties are included in this collection the more round trips to Active Directory are necessary to retrieve them.

我做了一些性能测试:

使用Microsoft样本取回200 InetOrgPerson对象了500ms左右。

Using the Microsoft sample to retrieve 200 InetOrgPerson objects took about 500ms.

直接使用DirectorySearcher类,只有请求的性质利息
只用了大约70毫秒(见下面的示例)

Using the DirectorySearcher class directly and only requesting the properties of interest took only 70ms (see sample below).

using (DirectoryEntry e = new DirectoryEntry("LDAP://server10/CN=users,DC=treyresearch,DC=net", 
                                         "treyresearch\\administrator", "P@$$W0rd", AuthenticationTypes.FastBind | AuthenticationTypes.Secure))
  {
    using (DirectorySearcher ds = new DirectorySearcher(e, "(&(objectCategory=inetorgperson)(logonCount=0))"))
    {
      ds.SearchScope = SearchScope.OneLevel;
      ds.PropertiesToLoad.Clear();
      ds.PropertiesToLoad.Add("logonCount");
      ds.PropertiesToLoad.Add("sAMAccountName");


      Stopwatch sw = new Stopwatch();
      sw.Start();
      int countPerson = 0;
      using (SearchResultCollection searchResultCol = ds.FindAll())
      {
        foreach (SearchResult sr in searchResultCol)
        {
          ResultPropertyValueCollection propCol = sr.Properties["logonCount"];

          if (propCol.Count > 0)
          {
            countPerson++;
            object cou = propCol[0];
          }
        }
        sw.Stop();
        Console.Out.WriteLine(sw.ElapsedMilliseconds);
        Console.Out.WriteLine(countPerson);
      }
    }
  }



同样我'已经使用objectCategory属性搜索过滤器,而不是对象类的
,因为objectCategory属性是所谓的索引属性。
访问索引属性比访问非索引属性更快。

By the same token I've used objectCategory in the search filter instead of objectClass because objectCategory is a so called indexed property. Accessing indexed properties is faster than accessing non indexed properties.

此外我指定AuthenticationTypes.FastBind改善
性能。

Furthermore I've specified AuthenticationTypes.FastBind to improve performance.

要进一步提高性能看这篇文章的 MSDN 中描述了如何创建高效的搜索查询。

To further improve performance see this article on MSDN describing how to create efficient search queries.

要总结,使用DirectorySearcher类和specifing只有属性你
兴趣creatly提高你的搜索性能(减少往返到Active Directory)。

To summarize, using DirectorySearcher class and specifing only the properties you are interested in creatly improves the performance of your search (reducing round trips to Active Directory).

希望,这有助于。

这篇关于检索广告自定义属性在一个批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆