本文整理汇总了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"]);
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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
}
示例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))
{
}
}
示例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));
}
示例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));
}
示例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
}
示例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));
}