public static void Main()
        {
            TestMethodLevelSecurity me = new TestMethodLevelSecurity();

             me.dataHolder = new MyClassWithTypeSecurity(1964,06,16);

             // Local computer zone starts with all environment permissions.
             me.RetrievePersonalInformation("[All permissions]");

             // Deny the write permission required by the type.
             EnvironmentPermission epw = new EnvironmentPermission(
            EnvironmentPermissionAccess.Write,"PersonalInfo");
             epw.Deny();

             // Even though the type requires write permission,
             // and you do not have it; you can get the data.
             me.RetrievePersonalInformation(
            "[No write permission (demanded by type)]");

             // Reset the permissions and try to get
             // data without read permission.
             CodeAccessPermission.RevertAll();

             // Deny the read permission required by the method.
             EnvironmentPermission epr = new EnvironmentPermission(
            EnvironmentPermissionAccess.Read,"PersonalInfo");
             epr.Deny();

             // The method requires read permission, and you
             // do not have it; you cannot get the data.
             me.RetrievePersonalInformation(
            "[No read permission (demanded by method)]");
        }
        public static void Main()
        {
            EnvironmentPermission envPermission = new EnvironmentPermission(
            EnvironmentPermissionAccess.Read,
            "COMPUTERNAME;USERNAME;USERDOMAIN");
             envPermission.Deny();

             //Test Deny and Assert interaction for LinkDemands and Demands.
             TestAssertAndDeny();

             //Test Deny's effects on code in different stack frame.
             TestDenyAndLinkDemand();

             //Test Deny's effect on code in same frame as deny.
             try
             {
            SomeSecuredMethods.MethodProtectedByLinkDemand();
            Console.WriteLine(
               "This Deny has no effect with LinkDemand-protected code.");
             }
             catch (SecurityException e)
             {
            Console.WriteLine("This Deny protected the library.{0}",e);
             }
        }
        public void RollingFlatFileTraceListenerReplacedEnviromentVariablesWillFallBackIfNotPrivilegesToRead()
        {
            string environmentVariable = "%USERPROFILE%";
            string fileName = Path.Combine(environmentVariable, "foo.log");

            EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.Unrestricted);
            denyPermission.Deny();

            try
            {
                RollingFlatFileTraceListener listener = new RollingFlatFileTraceListener(fileName, "header", "footer", null, 1, "", RollFileExistsBehavior.Increment, RollInterval.Day);
                listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
                listener.Dispose();
            }
            finally
            {
                EnvironmentPermission.RevertAll();
            }

            Assert.Fail("Permission was not denied.");
        }