DirectoryEntry的属性测试代码
public static DirectoryEntry FindOneDirectoryEntry(string strDomainName, string strFilter, SearchScope scSearchScope)
{
dbMessage = new dbAccessMessage();
AdInfo adinfo = Config.GetConfig(strDomainName);
DirectoryEntry de = null;
try
{
string path = "LDAP://" + adinfo.DomainControler + "/" + Utility.GetDomainDN(adinfo.RootDn);
DirectoryEntry root = new DirectoryEntry(path, adinfo.SuperUserName, adinfo.SuperUserPass);
DirectorySearcher srch = new DirectorySearcher();
srch.SearchRoot = root;
srch.Filter = strFilter;
srch.SearchScope = scSearchScope;
SearchResult sr = srch.FindOne();
if (sr != null)
{
de = sr.GetDirectoryEntry();
}
}
catch
{
}
return de;
}
aspx.cs
if (!Page.IsPostBack)
{
DirectoryEntry de = Utility.FindOneDirectoryEntry(strDomainName,strFilter,scSearchScope);
AdUserInfo aduserinfo=new AdUserInfo();
foreach (string property in de.Properties.PropertyNames)
{
/*
PropertyValueCollection valueCollection = de.Properties[property];
for (int i = 0; i < valueCollection.Count; i++)
{
msg.Text += property + ":" + valueCollection[i].ToString()+"<br/>";
}
* */
msg.Text += property + ":" + de.Properties[property].Value.ToString()+ "<br/>";
}
//aduserinfo = ADUser.GetUserInfo(de); ;
msg1.Text = aduserinfo.sAMAccountName;
}
注释代码的返回结果:
objectClass:top
objectClass:domain
objectClass:domainDNS
方法二的返回结果:
objectClass:System.Object[]
两个之间的关系是什么呢?至今未弄清楚。