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应用程序 –