當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。