Example #1
0
        public static List<AdGroup> GetUserAdGroups(User user)
        {
            List<AdGroup> result = new List<AdGroup>();

            // establish domain context
            PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain);

            // find your user
            UserPrincipal up = UserPrincipal.FindByIdentity(yourDomain, user.Login);

            // if found - grab its groups
            if (up != null)
            {
                //PrincipalSearchResult<Principal> groups = up.GetAuthorizationGroups();

                //// iterate over all groups
                //foreach (Principal p in groups)
                //{
                //    // make sure to add only group principals
                //        if (p is GroupPrincipal)
                //        {
                //            result.Add(new AdGroup() { SID = p.Sid.Value, Name = p.DisplayName });
                //        }
                //}

                PrincipalSearchResult<Principal> groups = up.GetAuthorizationGroups();

                var iterGroup = groups.GetEnumerator();
                using (iterGroup)
                {
                    while (iterGroup.MoveNext())
                    {
                        try
                        {
                            Principal p = iterGroup.Current;
                            //result.Add((GroupPrincipal)p);
                            result.Add(new AdGroup() { SID = p.Sid.Value, Name = p.DisplayName });
                        }
                        catch (PrincipalOperationException)
                        {
                            continue;
                        }
                    }
                }
            }

            return result;
        }
Example #2
0
        protected void Page_PreLoad(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (IsProxyUser)
                {
                    string proxySid = Request.QueryString[qspPrxusr];
                    User = new User(proxySid);
                }
                else
                {
                    User = new User(true);
                }

            }
        }