I'm using the below code, its working in my local. But its not working in DMZ server.
public string GetEmailByEmployeeId(string empID)
{
try
{
using (HostingEnvironment.Impersonate())
{
using (PrincipalContext adAuth = new PrincipalContext(ContextType.Domain, this.ADDomain))
{
UserPrincipal searchTemplate = new UserPrincipal(adAuth);
searchTemplate.EmployeeId = empID;
PrincipalSearcher ps = new PrincipalSearcher(searchTemplate);
UserPrincipal user = (UserPrincipal)ps.FindOne();
if (user != null)
{
return "Email: " + user.EmailAddress;
}
else
{
return "No Records Found";
}
};
}
}
catch (Exception e)
{
return e.ToString();
}
}
Getting below error: "System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server could not be contacted. ---> System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.