Set Principal Permission - CSharp Operating System

CSharp examples for Operating System:Windows

Description

Set Principal Permission


using System;
using System.Security.Permissions;

class MainClass
    {
        public static void Method1()
        {
            PrincipalPermission perm = new PrincipalPermission(@"MACHINE\Anya", null);
            perm.Demand();
        }

        public static void Method2()
        {
            PrincipalPermission perm1 = new PrincipalPermission(null, @"MACHINE\Managers");

            PrincipalPermission perm2 = new PrincipalPermission(null, @"MACHINE\Developers");

            perm1.Union(perm2).Demand();
        }

        public static void Method3()
        {
            PrincipalPermission perm = new PrincipalPermission(@"MACHINE\Anya", @"MACHINE\Managers");

            perm.Demand();
        }

        [PrincipalPermission(SecurityAction.Demand, Name = @"MACHINE\Anya")]
        public static void Method4()
        {
            // Method implementation...
        }

        [PrincipalPermission(SecurityAction.Demand, Role = @"MACHINE\Managers")]
        [PrincipalPermission(SecurityAction.Demand, Role = @"MACHINE\Developers")]
        public static void Method5()
        {
            // Method implementation...
        }

        [PrincipalPermission(SecurityAction.Demand, Name = @"MACHINE\Anya",
            Role = @"MACHINE\Managers")]
        public static void Method6()
        {
            // Method implementation...
        }
    }

Related Tutorials