我在'Alpha'域上部署了MVC 4 web應用程序,並且Web應用程序使用以下代碼獲取Windows用戶詳細信息。我們有3個不同的域(Alpha,Beta和Gamma)之間的信任關係。當名爲Beta\bloggs
登錄的用戶打開以下代碼時,網絡應用會返回alpha\bloggs
的詳細信息。有沒有辦法從活動目錄中獲取正確的用戶?MVC4 web從錯誤的Active Directory獲取用戶詳細信息。
在此先感謝。
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
using (UserPrincipal user = UserPrincipal.FindByIdentity(context, username))
{
if (user != null)
{
HttpContext.Current.Session["FullUserName"] = fullName;
HttpContext.Current.Session["EmailAddress"] = user.EmailAddress;
}
}
}
感謝您的答覆。我無法理解你的答案。你能解釋一下嗎?這是否意味着它不可能! – Scorpion
我相信你需要直接連接到你想查詢的AD服務器。 –