的作品在我的工作我必须处理2个不同的域x.com(父目录)和它的子域yxcomActive Directory查找但是局部
父域(x.com)拥有所有的活动目录用户,计算机等。从位于x.com域中的本地工作站,我可以阅读活动目录用户的电子邮件。
服务器位于域y.x.com中x的子域。在服务器上,活动目录读取失败,并且电子邮件地址未从活动目录中读取。
除此之外,我尝试从位于y.x.com域(与服务器相同)中的虚拟机执行相同的代码,但令我惊讶的是这起作用。
我使用的目录服务在.NET中做到这一点,我的代码如下:
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;
任何帮助,将不胜感激。
是否有错误讯息?如果是这样,请将其添加到您的问题(使用编辑链接)。 – Greg 2010-09-08 17:22:06