我想列出所有邮件列表或搜索我的 Active Directory 中存在的邮件 ID,因此如果我通过 Visual Studio 运行它但我发布或部署这些代码到IIS 服务器。
我的 C# 代码,
[HttpGet]
public JsonResult getADEmail(string query = "")
{
DirectorySearcher dirSearcher = new DirectorySearcher();
dirSearcher.Filter = "(&(objectClass=user)(objectcategory=person)(mail=" + query + "*))";
SearchResult srEmail = dirSearcher.FindOne();
SearchResultCollection SearchResultCollection = dirSearcher.FindAll();
string propName = "mail";
ResultPropertyValueCollection valColl = srEmail.Properties[propName];
List<string> results = new List<string>();
foreach (SearchResult sr in SearchResultCollection)
{
ResultPropertyValueCollection val = sr.Properties[propName];
results.Add(val[0].ToString());
}
return Json(results);
}
我本地的目录路径,
"LDAP://DC=arcadis-nl,DC=local" from (dirSearcher.SearchRoot.Path)
The IIS is on another server: 154:139:1:150
我哪里出错了?我应该怎么做才能解决这个问题?