【发布时间】:2015-06-14 14:39:41
【问题描述】:
我正在尝试使用 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 应用程序中执行此操作的吗?
-
是的,我是。我正在使用 asp 应用程序
标签: c# active-directory active-directory-group