https://files.cnblogs.com/files/shexunyu/%E5%9F%9F%E8%B4%A6%E6%88%B7%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95%E9%AA%8C%E8%AF%81.zipdom
public class VerifyUserByDomain
{
public static bool verify(string userName, string pwd, string domain)
{
bool boolResult = false;
try
{
//鏈接域,path一般是:"LDAP://****";****爲域的名字(通常是大寫的英文字符串)
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + domain, userName, pwd);
//string strFilter = "(&(objectCategory=person)(objectClass=user))";
string strFilter = string.Format("(&(objectClass=user)(samAccountName={0}))", userName);
DirectorySearcher objSearcher = new DirectorySearcher(dirEntry, strFilter);
SearchResult result = objSearcher.FindOne();orm
boolResult = true;
}
catch (Exception ex)
{
throw ex;
}
return boolResult;
}
}blog