1
我的第一个项目是为我们的Active Directory创建一个Web工具。我需要做的一件事就是获取并显示在Active Directory中的用户帐户的“MemberOf”选项卡中显示的组,并将其传递给gridview。我做了一些家庭工作,这里是我的。如何获取Active Directory中“成员”选项卡中的组
我有一个文本框(txtusername),右边是一个按钮(“此用户的搜索组”)。
这里是我的代码:
protected void btnsearch_Click(object sender, EventArgs e)
{
ADMAM.GetUserGroups(txtusername.Text, Session["WindowsID"].ToString(), Session["Password"].ToString());
}
public DataTable GetUserGroups(string sUserName, string windowsid, string password)
{
DataTable dt = new DataTable();
UserPrincipal oUserPrincipal = GetUser(sUserName, windowsid, password);
PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();
foreach (Principal oResult in oPrincipalSearchResult)
{
dt.Rows.Add(oResult.Name);
dt.AcceptChanges();
}
return dt;
}
我还是不能让“成员”的选项卡里面的群体。
嗨marc_s 感谢您的专业意见。我尝试了你的建议...但是,我仍然无法获得成员标签中的组。 Vice Versa,我能够得到一个OU的成员。我的目标是获得用户所属的会员资格。我试图搜索我的帐户,这是8-10组的成员。但是他们没有出现在我的查询中。有什么我忽视或滥用(可能有)? 感谢您的回复!非常感谢! – Joel 2013-03-16 02:19:52