zoukankan      html  css  js  c++  java
  • DirectoryEntry的属性测试代码

     public static DirectoryEntry FindOneDirectoryEntry(string strDomainName, string strFilter, SearchScope scSearchScope)
            {
                dbMessage = new dbAccessMessage();
                AdInfo adinfo = Config.GetConfig(strDomainName);
                DirectoryEntry de = null;
                try
                {
                    string path = "LDAP://" + adinfo.DomainControler + "/" + Utility.GetDomainDN(adinfo.RootDn);
                    DirectoryEntry root = new DirectoryEntry(path, adinfo.SuperUserName, adinfo.SuperUserPass);
                    DirectorySearcher srch = new DirectorySearcher();
                    srch.SearchRoot = root;
                    srch.Filter = strFilter;
                    srch.SearchScope = scSearchScope;
                    SearchResult sr = srch.FindOne();

                    if (sr != null)
                    {

                        de = sr.GetDirectoryEntry();
                    }

                }
                catch
                {
                }
                return de;
            }

    aspx.cs

            if (!Page.IsPostBack)
            {
                DirectoryEntry de = Utility.FindOneDirectoryEntry(strDomainName,strFilter,scSearchScope);
                AdUserInfo aduserinfo=new AdUserInfo();
                foreach (string property in de.Properties.PropertyNames)
                {
                    /*
                    PropertyValueCollection valueCollection = de.Properties[property];
                    for (int i = 0; i < valueCollection.Count; i++)
                    {
                        msg.Text += property + ":" + valueCollection[i].ToString()+"<br/>";
                    }
                     * */
                    msg.Text += property + ":" + de.Properties[property].Value.ToString()+ "<br/>";
                }
                //aduserinfo = ADUser.GetUserInfo(de); ;
                msg1.Text = aduserinfo.sAMAccountName;
            }

    注释代码的返回结果:

    objectClass:top
    objectClass:domain
    objectClass:domainDNS

    方法二的返回结果:

    objectClass:System.Object[]

    两个之间的关系是什么呢?至今未弄清楚。

  • 相关阅读:
    让EditPlus支持SQL高亮提示
    SQL Server 触发器
    asp.net中使用Global.asax文件中添加应用出错代码,写入系统日志文件或数据库
    C#钩子类 几乎捕获键盘鼠标所有事件
    DataGridView一些常用操作
    在C#中实现串口通信的方法
    System.Diagnostics.Process.Start的妙用
    Byte[]、Image、Bitmap 之间的相互转换
    Dos命令打印文件以及Dos打印到USB打印端口
    Winform常用的一些功能收集(持续更新)
  • 原文地址:https://www.cnblogs.com/xyzyyj/p/2856691.html
Copyright © 2011-2022 走看看