活动目录findone()方法 [英] active directory findone() method

查看:97
本文介绍了活动目录findone()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此line`s询问广告

 的DirectoryEntry德= NULL;
            信息搜索结果的结果= NULL;
            DE =新的DirectoryEntry();

            //歌厅结果从公元
            de.Path = dr.manager;
            de.AuthenticationType = AuthenticationTypes.Secure;
            DirectorySearcher从搜索=新DirectorySearcher从(日);
            sea​​rch.Filter =的String.Format((objectClass的= {0}),*);
            sea​​rch.PropertiesToLoad.Add(IsraelID);
            结果= search.FindOne();
            德= results.GetDirectoryEntry();
 

但即时在findone得到一个异常()

  System.Runtime.InteropServices.COMException(0x80004005的):未指定错误

   在System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)
   在System.DirectoryServices.DirectoryEntry.Bind()
   在System.DirectoryServices.DirectoryEntry.get_AdsObject()
   在System.DirectoryServices.DirectorySearcher.FindAll(布尔findMoreThanOne)
   在System.DirectoryServices.DirectorySearcher.FindOne()
 

解决方案

 字符串LDAP =LDAP:// DC = MYDOMAIN,DC = COM;
使用(的DirectoryEntry dirEntry =新的DirectoryEntry(LDAP,NULL,NULL,AuthenticationTypes.Secure))
    使用(DirectorySearcher从dirSearch =新DirectorySearcher从(
        dirEntry,
        string.Concat((objectClass的= *)),
        新的String [] {IsraelID}))
    {
        信息搜索结果的结果= dirSearch.FindOne();
        如果(结果!= NULL)
            返回result.Properties [IsraelID] [0]的ToString();
        其他
            返回null;
    }
 

注意:的string.Concat()围绕(对象类= *)语句是存在的,因为这是常见的添加其他语句或变量有

请确保你有一个正确的LDAP字符串,我建议使用的语句,以确保您处理一切之后。

im trying to inquire Ad by using this line`s

            DirectoryEntry de = null;
            SearchResult results = null;
            de = new DirectoryEntry();

            //geting the result FROM ad
            de.Path = dr.manager;
            de.AuthenticationType = AuthenticationTypes.Secure;
            DirectorySearcher search = new DirectorySearcher(de);
            search.Filter = string.Format("(objectClass={0})",'*');
            search.PropertiesToLoad.Add("IsraelID");
            results = search.FindOne();
            de = results.GetDirectoryEntry();

but im getting an exception in the findone()

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error

   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
   at System.DirectoryServices.DirectorySearcher.FindOne()

解决方案

string LDAP = "LDAP://DC=MYDOMAIN,DC=COM";
using (DirectoryEntry dirEntry = new DirectoryEntry(LDAP, null, null, AuthenticationTypes.Secure))
    using (DirectorySearcher dirSearch = new DirectorySearcher(
        dirEntry,
        string.Concat("(objectClass=*)"),
        new string[] { "IsraelID" }))
    {
        SearchResult result = dirSearch.FindOne();
        if (result != null)
            return result.Properties["IsraelID"][0].ToString();
        else
            return null;
    }

Note: The string.Concat() around the "(objectClass=*)" statement is there because It's common to add additional statements or variables there.

Make sure you have a proper LDAP string, and I would suggest using statements to make sure you dispose of everything afterwards.

这篇关于活动目录findone()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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