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>");
}
}
}
}
}
}