的作品在我的工作我必須處理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