4

我有一個配置爲使用Windows身份驗證的asp.net MVC應用程序。我正在嘗試使用這個從UserPrincipal獲取組。適用於Windows的AD用戶組

UserPrincipal.Current.GetGroups() 

這適用於從Visual Studio運行但在IIS上承載時失敗。應用程序池配置爲集成管道和網絡服務標識。下面拋出錯誤:

Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'."

我試圖冒充代碼

WindowsIdentity identity = (WindowsIdentity)HttpContext.Current.User.Identity; 

using (WindowsImpersonationContext wic = identity.Impersonate()) 
{ 
    PrincipalContext context = new PrincipalContext(ContextType.Domain, "DOMAIN NAME"); 
    UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "User Name"); 

} 

FindByIdentity拋出錯誤。

000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1

如何從AD獲取當前用戶組?

+0

你是怎麼解決這個問題的? – Bargitta 2016-02-05 06:42:22

回答

0

我結束了這個問題,因爲我不小心讓我的IIS網站的身份驗證類型設置錯誤。我刪除了「匿名身份驗證」,並設置了它,因此只有「asp.net身份驗證」和「Windows身份驗證」已啓用,並且錯誤消失。

相關問題