zoukankan      html  css  js  c++  java
  • 列出域中所有用户的代码 dodo

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.DirectoryServices;

    namespace WebAppLDAP
    {
        
    public partial class _Default : System.Web.UI.Page
        
    {
            
    protected void Page_Load(object sender, EventArgs e)
            
    {
                
    //ListAllUser();
                 showUser();
             }

            
    protected void showUser()
            
    {
                 DirectoryEntry entry
    = new DirectoryEntry("LDAP://ABC.COM.CN");
                 System.DirectoryServices.DirectorySearcher mySearcher
    = new System.DirectoryServices.DirectorySearcher(entry);

                 mySearcher.Filter
    = "(&(objectClass=user)(objectCategory=person))";

                 mySearcher.PropertiesToLoad.Add(
    "name"); //用户名
                 mySearcher.PropertiesToLoad.Add("samaccountname"); //用户帐号

                 SearchResultCollection resultCol
    = mySearcher.FindAll();

                
    foreach (SearchResult result in resultCol)
                
    {
                     ResultPropertyCollection props
    = result.Properties;

                    
    foreach (string propName in props.PropertyNames)
                    
    {
                        
    //Response.Write(props[propName][0] + "<BR>");
                        if (propName == "name")
                        
    {
                             Response.Write(props[propName][
    0] + "<BR>");
                         }

                        
    if (propName == "samaccountname")
                        
    {
                             Response.Write(props[propName][
    0] + "<BR><BR>");
                         }

                     }

                 }

             }

         }

    }

  • 相关阅读:
    Linux 添加环境变量
    postgresql 获取修改列的值
    5月30日周一上午
    周日5月29日
    2016年5月26日
    如何使用Gson(添加到项目里去)
    linux内核分析课程总结()待完善
    5月5日离散课笔记
    4月28日的离散课(还少了一部分)
    2016年4月29日
  • 原文地址:https://www.cnblogs.com/zgqys1980/p/1281847.html
Copyright © 2011-2022 走看看