当前位置: 首页>>代码示例>>C#>>正文


C# PermissionSet.Deny方法代码示例

本文整理汇总了C#中System.Security.PermissionSet.Deny方法的典型用法代码示例。如果您正苦于以下问题:C# PermissionSet.Deny方法的具体用法?C# PermissionSet.Deny怎么用?C# PermissionSet.Deny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.PermissionSet的用法示例。


在下文中一共展示了PermissionSet.Deny方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReflectionFormatterReadSecurityExceptionPropertiesWithoutPermissionTest

        public void ReflectionFormatterReadSecurityExceptionPropertiesWithoutPermissionTest()
        {
            SecurityPermission denyPermission
                = new SecurityPermission(SecurityPermissionFlag.ControlPolicy | SecurityPermissionFlag.ControlEvidence);
            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(denyPermission);
            permissions.Deny();

            StringBuilder sb = new StringBuilder();
            StringWriter writer = new StringWriter(sb);

            SecurityException exception = null;
            try
            {
                DemandException(denyPermission);
            }
            catch (SecurityException e)
            {
                exception = e;
            }

            MockTextExceptionFormatter formatter = new MockTextExceptionFormatter(writer, exception, Guid.Empty);
            formatter.Format();

            CodeAccessPermission.RevertDeny();

            formatter = new MockTextExceptionFormatter(writer, exception, Guid.Empty);
            formatter.Format();
            Assert.AreEqual(exception.Demanded.ToString(), formatter.properties["Demanded"]);
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:30,代码来源:ExceptionFormatterFixture.2008.cs

示例2: CanReflectOnSecurityExceptionWithoutPermission

		public void CanReflectOnSecurityExceptionWithoutPermission()
		{
			SecurityPermission denyPermission
				= new SecurityPermission(SecurityPermissionFlag.ControlPolicy | SecurityPermissionFlag.ControlEvidence);
			PermissionSet permissions = new PermissionSet(PermissionState.None);
			permissions.AddPermission(denyPermission);
			permissions.Deny();

			SecurityException exception = null;
			try
			{
				DemandException(denyPermission);
			}
			catch (SecurityException e)
			{
				exception = e;
			}
			
			ExceptionFormatter formatter = new ExceptionFormatter();

			String message = formatter.GetMessage(exception);
			Match demandedMatch = DemandedEntryRegex.Match(message);
			Assert.IsNotNull(demandedMatch);
			Assert.AreEqual(Resources.PropertyAccessFailed, demandedMatch.Groups[1].Value);

			CodeAccessPermission.RevertDeny();

			message = formatter.GetMessage(exception);
			demandedMatch = DemandedEntryRegex.Match(message);
			Assert.IsNotNull(demandedMatch);
			Assert.AreNotEqual(Resources.PropertyAccessFailed, demandedMatch.Groups[1].Value);
		}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:32,代码来源:ExceptionFormatterFixture.cs

示例3: GetMachineNameWithoutPermissions

        /// <summary>
        /// Try/finally is completely unnecessary. Permissions are associated with stack frames
        /// and go out of scope once stack frame returns.
        /// </summary>
        private string GetMachineNameWithoutPermissions()
        {
            EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.None);

            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(denyPermission);
            permissions.Deny();

            try
            {
                return Environment.MachineName;
            }
            finally
            {
                CodeAccessPermission.RevertDeny();
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:21,代码来源:CasFixture.cs

示例4: NoPermissionToReadFileWhenCreated

        public void NoPermissionToReadFileWhenCreated()
        {
            FileIOPermission denyPermission =
                new FileIOPermission(FileIOPermissionAccess.Read, Path.GetFullPath("TestFile"));

            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(denyPermission);
            permissions.Deny();

            try
            {
                new FileDependency("TestFile");
            }
            finally
            {
                CodeAccessPermission.RevertDeny();
            }
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:18,代码来源:FileDependencyFixture.2008.cs

示例5: NoPermissionToReadWhenCheckingExpiration

        public void NoPermissionToReadWhenCheckingExpiration()
        {
            FileDependency dependency = new FileDependency("TestFile");

            FileIOPermission denyPermission =
                new FileIOPermission(FileIOPermissionAccess.Read, Path.GetFullPath("TestFile"));

            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(denyPermission);
            permissions.Deny();

            try
            {
                dependency.HasExpired();
            }
            finally
            {
                CodeAccessPermission.RevertDeny();
            }
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:20,代码来源:FileDependencyFixture.2008.cs

示例6: Deny_NonCasPermission

		public void Deny_NonCasPermission ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.None);
			ps.AddPermission (new PrincipalPermission (PermissionState.None));
			Assert.IsTrue (ps.ContainsNonCodeAccessPermissions (), "ContainsNonCodeAccessPermissions");
			Assert.AreEqual (1, ps.Count, "Count");
			ps.Deny ();
			// it's simply ignored
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:9,代码来源:PermissionSetTest.cs

示例7: OpenMachineConfigWithoutPermissions

 public void OpenMachineConfigWithoutPermissions()
 {
     FileIOPermission denyPermission = new FileIOPermission(FileIOPermissionAccess.Read, ConfigurationBuilder.MachineConfigurationFile);
     PermissionSet permissions = new PermissionSet(PermissionState.None);
     permissions.AddPermission(denyPermission);
     permissions.Deny();
     using (new ConfigurationBuilder(ConfigurationBuilder.MachineConfigurationFile))
     {
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:10,代码来源:ConfigurationBuilderFixture.cs

示例8: CanGetMachineNameWithoutSecurity

		public void CanGetMachineNameWithoutSecurity()
		{
			EnvironmentPermission denyPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, computerName);
			PermissionSet permissions = new PermissionSet(PermissionState.None);
			permissions.AddPermission(denyPermission);
			permissions.Deny();

			StringBuilder sb = new StringBuilder();
			StringWriter writer = new StringWriter(sb);
			Exception exception = new MockException();
			TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception);
			Assert.IsTrue(sb.Length == 0);
			formatter.Format();

			Assert.IsTrue(sb.ToString().Contains(machineName + " : " + permissionDenied));
		}
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:16,代码来源:ExceptionFormatterFixture.cs

示例9: CanGetWindowsIdentityWithoutSecurity

		public void CanGetWindowsIdentityWithoutSecurity()
		{
			SecurityPermission denyPermission = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
			PermissionSet permissions = new PermissionSet(PermissionState.None);
			permissions.AddPermission(denyPermission);
			permissions.Deny();

			StringBuilder sb = new StringBuilder();
			StringWriter writer = new StringWriter(sb);
			Exception exception = new MockException();
			TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception);
			Assert.IsTrue(sb.Length == 0);
			formatter.Format();
			Console.WriteLine(sb.ToString());
			Assert.IsTrue(sb.ToString().Contains(windowsIdentity + " : " + permissionDenied));
		}				
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:16,代码来源:ExceptionFormatterFixture.cs

示例10: Deny_NonCasPermission

		public void Deny_NonCasPermission ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.None);
			ps.AddPermission (new PrincipalPermission (PermissionState.None));
			Assert ("ContainsNonCodeAccessPermissions", ps.ContainsNonCodeAccessPermissions ());
			AssertEquals ("Count", 1, ps.Count);
			ps.Deny ();
			// it's simply ignored
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:9,代码来源:PermissionSetTest.cs

示例11: OpenConfigFileWithoutPermissions

        public void OpenConfigFileWithoutPermissions()
        {
            FileIOPermission denyPermission =
                new FileIOPermission(FileIOPermissionAccess.Read, Path.GetFullPath(myConfigTestFile));

            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(denyPermission);
            permissions.Deny();
            ConfigurationFile configFile = new ConfigurationFile();
            configFile.Load(Path.GetFullPath(myConfigTestFile));
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:11,代码来源:ConfigurationFileFixture.cs


注:本文中的System.Security.PermissionSet.Deny方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。