Very briefly then this is my situation. At my workplace I have to deal with 2 different domains x.com (the parent directory) and it's subdomain y.x.com
The parent domain(x.com) has all the active directory users, computers etc. From my local workstation which sits in the x.com domain i can read emails for the active directory users just fine.
The server sits in domain y.x.com a sub domain of x. On the server the active directory read is failing and the email address is not being read from active directory.
In addition to this i tried to the same code from a virtual machine which sits in the y.x.com domain (same as the server) and to my surprise this worked.
I am using directory services in .NET to do this and my code is below:
string userEmail = string.Empty;
try
{
accountName = accountName.Replace(ConfigurationManager.AppSettings["DomainName"].ToString(), "");
DirectorySearcher ds = new DirectorySearcher()
{
SearchRoot = new DirectoryEntry()
{
Path = ConfigurationManager.AppSettings["DirectoryPath"].ToString(),
AuthenticationType = AuthenticationTypes.Secure
}
};
ds.Filter = "(SAMAccountName=" + accountName + ")";
ds.PropertiesToLoad.Add(ConfigurationManager.AppSettings["ADMailPropertyName"].ToString());
SearchResult result = ds.FindOne();
if (result != null)
{
userEmail = result.Properties[ConfigurationManager.AppSettings["ADMailPropertyName"].ToString()][0].ToString();
}
}
catch (Exception e)
{
//Log error
}
return userEmail;
Any help would be greatly appreciated as this is an urgent matter that need to be resolved.