当前位置: 首页>>代码示例>>C#>>正文


C# UserPrincipal.IsMemberOf方法代码示例

本文整理汇总了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);
 }
开发者ID:bolenc,项目名称:Active-Directory-Examples,代码行数:11,代码来源:ActiveDirectory.cs

示例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();
        }
开发者ID:aleks19921015,项目名称:UnitApis,代码行数:27,代码来源:AdHelper.cs

示例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;
        }
开发者ID:rcanright,项目名称:pgina,代码行数:34,代码来源:LocalAccount.cs


注:本文中的System.DirectoryServices.AccountManagement.UserPrincipal.IsMemberOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。