[英]DirectorySearcher working in Local but not working in IIS server
我想列出所有邮件列表或搜索我的 Active 目录中存在的邮件 ID,所以我已经使用 DirectorySearcher 如下所示并在我的本地系统中工作,如果我通过 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
我哪里出错了?我应该怎么做才能解决这个问题?。
这似乎是一个目录权限问题。需要检查的几件事:
在这种情况下,我们必须将应用程序池的身份设置为有权访问目录的用户。
补充参考:
https://www.codeproject.com/Tips/599697/Get-list-of-Active-Directory-users-in-Csharp
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.