Beispiel #1
0
        private static void RemovePolicy(string path, string name)
        {
            //Get a reference to the User level "All Code" group.
            PolicyLevel polLevel = GetPolicy(_user);

            if (polLevel != null)
            {
                UnionCodeGroup allCodeCG =
                    (UnionCodeGroup)polLevel.RootCodeGroup;

                //Determine the resolved membership condition for the
                //specified path.
                string resolvedPath =
                    new UrlMembershipCondition(path).ToString();

                //Locate a code group with the same name, the same resolved
                //path, and FullTrust; if found, remove the child group.
                IEnumerator cgs = allCodeCG.Children.GetEnumerator();
                while (cgs.MoveNext())
                {
                    CodeGroup cg = (CodeGroup)cgs.Current;
                    if (cg.Name == name)
                    {
                        if (cg.MembershipCondition.ToString() == resolvedPath &&
                            allCodeCG.PermissionSetName == _fullTrust)
                        {
                            allCodeCG.RemoveChild(cg);
                            SecurityManager.SavePolicy();
                            break;
                        }
                    }
                }
            }
        }