星宿.net

星星的随笔

博客园 首页 新随笔 联系 订阅 管理
   
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>");
                    }

                }

            }

        }

    }

}

posted on 2007-05-10 16:12  星宿.NET  阅读(869)  评论(1编辑  收藏  举报