public SearchResultCollection SearchLDAPUser(string _username, string _password)
{
try
{
//DirectoryEntry entry = new DirectoryEntry(this.path, _username, _password, AuthenticationTypes.Secure);
DirectoryEntry entry = new DirectoryEntry("XXXXXXXXXXXXXXX", "XXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXX", AuthenticationTypes.Secure); DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = "(objectClass=User)";
searcher.SearchScope = SearchScope.Subtree;
searcher.PropertiesToLoad.Add(this.LDAP_PROP_COMMON_NAME);
searcher.PropertiesToLoad.Add(this.LDAP_PROP_DISPLAY_NAME);
searcher.PropertiesToLoad.Add(this.LDAP_PROP_EMAIL_NAME);
searcher.PropertiesToLoad.Add("objectClass");
searcher.PropertiesToLoad.Add("UserPassword");
searcher.PropertiesToLoad.Add(this.LDAP_PROP_LASTNAME);
searcher.PropertiesToLoad.Add(this.LDAP_PROP_FIRSTNAME);
searcher.PropertiesToLoad.Add(this.LDAP_PROP_ADDRESS);
searcher.PropertiesToLoad.Add(this.LDAP_PROP_PROVINCE);
searcher.PropertiesToLoad.Add(this.LDAP_PROP_COUNTRY);
searcher.PropertiesToLoad.Add(this.LDAP_PROP_PHONE);
searcher.CacheResults = (true);
searcher.ReferralChasing = ReferralChasingOption.All;
SearchResultCollection result = searcher.FindAll();
searcher.Dispose();
return result;
}
catch (Exception E)
{
this.Response.Write(E.ToString());
return null;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SearchResultCollection sr = SearchLDAPUser(this.TextBox1.Text, "");
if (sr.Count>0)
{
this.Response.Write("GOOD!<br/>");
this.Response.Write(sr.Count.ToString());
int i = 0;
string str = "";
foreach (SearchResult sr1 in sr)
{
TODO(sr1);
}
this.Response.Write(str);
}
else
{
this.Response.Write("null");
} }
void TODO(SearchResult sr)
{
string str = "";
System.DirectoryServices.ResultPropertyCollection props = sr.Properties;
foreach (string name in props.PropertyNames)
{
foreach (object o in props[name])
{
str += name.ToString() + ":" + o.ToString() + "<br/>";
}
}
this.Response.Write(str);
this.Response.Write("<hr/><br/>");
}
里面的密码是AD管理员的密码
有办法没有???
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货