我使用下面的代码,它在我的本地工作。但它不适用于DMZ服务器。
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();
}
}
获取以下错误:" System.DirectoryServices.AccountManagement.PrincipalServerDownException:无法联系服务器。 ---> System.DirectoryServices.Protocols.LdapException:LDAP服务器不可用。