0
我試圖用c#代碼獲取活動目錄中的所有用戶組。從C#中的活動目錄中獲取所有用戶的組
這是我的代碼:
private List<GroupPrincipal> GetGroups()
{
string userName = User.Identity.Name;
string host = Request.Url.Host.ToLower();
List<GroupPrincipal> result = new List<GroupPrincipal>();
UserPrincipal user = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain, host), IdentityType.SamAccountName, userName);
foreach (GroupPrincipal group in user.GetGroups())
{
result.Add(group);
}
return result;
}
我是由該說,該服務器無法連接UserPrincipal用戶啓動該行收到一個錯誤。我從服務器上運行我的代碼,以便連接它。
我到底做錯了什麼?
預先感謝您!
你從Web應用程序這樣做呢? – Garett
是的,我是。我正在使用asp應用程序 –