zoukankan      html  css  js  c++  java
  • 记录:查看Active Directory里的用户的属性

     

    Code

     

    // LDAP路径:这里的路径格式要求"LDAP://lhvm.com/ OU=价格中心,DC=lhvm,DC=com "

    private static readonly string strADPath = ConfigurationManager.AppSettings["ADPath"].ToString();

    // 角色模拟的用户名,最好是管理员名

    private static readonly string strADUser = ConfigurationManager.AppSettings["ADAdminUser"].ToString();

    // 角色模拟的用户密码

    private static readonly string strADPassword = ConfigurationManager.AppSettings["ADPassword"].ToString();

    // 当前域的域名

    private static readonly string strADDomain = ConfigurationManager.AppSettings["ADDomain"].ToString();

     

    public static void TestSearch(string keyword)

    {

        string filter = string.Format("(&(|(objectCategory=person))(displayname=*{0}*))", keyword);

     

        try

        {

            DirectorySearcher searcher = new DirectorySearcher();

            searcher.SearchRoot = new DirectoryEntry(strADPath, strADUser, strADPassword);

            searcher.SearchScope = SearchScope.Subtree;

            searcher.Filter = filter;

            SearchResultCollection results = searcher.FindAll();

     

            if (results.Count > 0)

            {

                SearchResult result = results[0];

                foreach (object o in result.Properties.PropertyNames)

                {

                    Console.WriteLine( o.ToString()+" : "+result.Properties[o.ToString()][0]);

                }

                byte[] bs,bs1 = new byte[] { };

                bs = (byte[])result.Properties["objectsid"][0];

                bs1 = (byte[])result.Properties["objectguid"][0];

            }

        }

        catch (Exception ex)

        {

            LogHelper.WriteException(ex);

        }

    }

     

    App.config文件:

    <appSettings>

            <add key="ADPath" value="LDAP://DC=DevForMossVM,DC=com"/>

            <add key="ADAdminUser" value="DevForMossVM\administrator"/>

            <add key="ADPassword" value="abc-123"/>

            <add key="ADDomain" value="DevForMossVM.com"/>

    </appSettings>

     

    运行结果:

     

     

  • 相关阅读:
    vue--vuex详解
    vue2.0的一个小demo,
    vue---子调父 $emit (把子组件的数据传给父组件)
    高阶函数总结
    三个方法(apply、call、bind)
    JS的一些总结(函数声明和函数表达式的区别,函数中的this指向的问题,函数不同的调用方式,函数也是对象,数组中的函数调用)
    原型对象(下)
    案例:贪吃蛇
    原型对象(上)
    案例(拖拽对话框、高清放大镜、自制滚动条、元素的隐藏方式、表格隔行变色、tab切换效果、字符串拼接、刷新评论)
  • 原文地址:https://www.cnblogs.com/LeimOO/p/1559258.html
Copyright © 2011-2022 走看看