zoukankan      html  css  js  c++  java
  • novell.directory.ldap获取邮箱活动目录

    在windows系统上可以使用下列方法来查找所有的员工邮箱和员工组:

     1 StringDictionary ReturnArray = new StringDictionary();
     2                 Dictionary<string, string> resultDict = new Dictionary<string, string>();
     3                 DirectoryEntry deDirEntry = new DirectoryEntry("LDAP://mail.test.com",
     4                                                                    UserName,
     5                                                                    Password,
     6                                                                    AuthenticationTypes.Secure);
     7 
     8                 
     9 
    10                 DirectorySearcher mySearcher = new DirectorySearcher(deDirEntry);
    11                 
    12                 string sFilter = String.Format("(&(mailnickname=*)(|(objectcategory=user)(objectcategory=group)))");//(objectcategory=user)(objectcategory=group)
    13 
    14                 mySearcher.Filter = sFilter;
    15                 mySearcher.Sort.Direction = System.DirectoryServices.SortDirection.Ascending;
    16                 mySearcher.Sort.PropertyName = "cn";
    17                 mySearcher.PageSize = 1000;
    18 
    19                 SearchResultCollection results;
    20                 results = mySearcher.FindAll();
    View Code

    但是在移动端使用xamarin开发的时候是不能用上面的类的,需要使用其他的类库。

    下面推荐使用novell.directory.ldap类库,可以在NuGet上搜索LDAP即可查到,在我们安装程序包时可能遇到在PCL(可移植的)上无法安装,没关系,我们可以单独只装各平台的代码就可以了,虽然写的代码一样,但是就是要分平台来写,下面是例子:

     1 cn.Connect("mail.test.com", 389);
     2                 cn.Bind("test@test.com", "**password**");
     3                 string sFilter = String.Format("(&(mailnickname=*)(|(objectcategory=user)(objectcategory=group)))");
     4                 LdapSearchResults ldapSearchResults = cn.Search("CN=Users,DC=corp,DC=test,DC=com", LdapConnection.SCOPE_SUB, sFilter, null, false);
     5                 var entries = new List<LdapEntry>();
     6                 try
     7                 {
     8                     while (ldapSearchResults.hasMore())
     9                     {
    10                         entries.Add(ldapSearchResults.next());
    11                     }
    12                 }
    13                 catch (LdapException ex)
    14                 {
    15                     System.Console.WriteLine(ex.LdapErrorMessage);
    16                 }
    View Code

    注意事项,使用novell.directory.ldap时,有部分帐号无法连接。Search的参数请根据实际情况配置。

  • 相关阅读:
    根据excel表格中的某一列内容,使用python将其拆分成多个excel表格
    Python操作excel
    opensips(三):load_balancer与NAT
    opensips(二):NAT官方脚本
    sip头域
    OPensips(一):NAT例子
    四、word2vec + siameseLSTM改进(1)
    三、word2vec + siameseLSTM
    二、LSTM处理不定长句子
    一、word2vec的使用
  • 原文地址:https://www.cnblogs.com/zuimengaitianya/p/7059949.html
Copyright © 2011-2022 走看看