Reputation: 1416
I want to list the all mail list or search a mail id present in my Active directory so I have used the DirectorySearcher like following and working in my local system if I run it via visual studio but not working when I publish or deploy these code to an IIS server.
My C# Code,
[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);
}
Directory Path in my local,
"LDAP://DC=arcadis-nl,DC=local" from (dirSearcher.SearchRoot.Path)
The IIS is on another server: 154:139:1:150
Where I did go wrong?What should I do to resolve this issue?.
Upvotes: 0
Views: 1053
Reputation: 5294
It seems like a directory permissions problem.Few things to check:
In these kind of scenario , we have to set the identity of the application pool to a user who has access to the directory.
Additional reference:
https://www.codeproject.com/Tips/599697/Get-list-of-Active-Directory-users-in-Csharp
Hope it helps.
Upvotes: 0