本文整理汇总了C#中System.DirectoryServices.AccountManagement.UserPrincipal.IsMemberOf方法的典型用法代码示例。如果您正苦于以下问题:C# UserPrincipal.IsMemberOf方法的具体用法?C# UserPrincipal.IsMemberOf怎么用?C# UserPrincipal.IsMemberOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DirectoryServices.AccountManagement.UserPrincipal
的用法示例。
在下文中一共展示了UserPrincipal.IsMemberOf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsInGroup
/// <summary>
/// Returns true if the user is in the specified group
/// </summary>
/// <param name="adUser">The user</param>
/// <param name="groupName">The ID of the group to check for membership</param>
/// <returns></returns>
public bool IsInGroup(UserPrincipal adUser, string groupName)
{
GroupPrincipal g = GroupPrincipal.FindByIdentity(Context, groupName);
return adUser.IsMemberOf(g);
}
示例2: GetMbrPath
private static string GetMbrPath(UserPrincipal usr)
{
Stack<string> output = new Stack<string>();
StringBuilder retVal = new StringBuilder();
GroupObj fg = null, tg = null;
output.Push(usr.Name);
foreach (GroupObj go in _groups)
{
if (usr.IsMemberOf(go.Group))
{
output.Push(go.Group.Name);
fg = go;
while (fg.Parent != null)
{
output.Push(fg.Parent.Name);
tg = (from g in _groups where g.Group == fg.Parent select g).FirstOrDefault();
fg = tg;
}
break;
}
}
while (output.Count > 1)
retVal.AppendFormat("{0} ->", output.Pop());
retVal.Append(output.Pop());
return retVal.ToString();
}
示例3: GetGroups
/// <summary>
/// Returns a list of groups of which the user is a member. It does so in a fashion that
/// may seem strange since one can call UserPrincipal.GetGroups, but seems to be much faster
/// in my tests.
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
private static List<GroupPrincipal> GetGroups(UserPrincipal user)
{
List<GroupPrincipal> result = new List<GroupPrincipal>();
// Get all groups using a PrincipalSearcher and
GroupPrincipal filter = new GroupPrincipal(m_machinePrincipal);
using (PrincipalSearcher searcher = new PrincipalSearcher(filter))
{
PrincipalSearchResult<Principal> sResult = searcher.FindAll();
foreach (Principal p in sResult)
{
if (p is GroupPrincipal)
{
GroupPrincipal gp = (GroupPrincipal)p;
if (user.IsMemberOf(gp))
result.Add(gp);
else
gp.Dispose();
}
else
{
p.Dispose();
}
}
}
return result;
}