Csharp/C Sharp by API/System.Security.Permissions/SecurityAction

Материал из .Net Framework эксперт
Версия от 12:11, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

SecurityAction.Demand

 
using System;
using System.IO;
using System.Security.Permissions;
[PrincipalPermissionAttribute(SecurityAction.Demand, Role="Administrators")]
class MainClass
{
  public static void Main() 
  {
    FileStream fsOut = File.Create(@"c:\\temp\\test.txt");
    StreamWriter sw = new StreamWriter(fsOut);
    sw.WriteLine("str");
    sw.Flush();
    sw.Close();
  }
}


SecurityAction.InheritanceDemand

 

using System.Security.Permissions;
[PublisherIdentityPermission(SecurityAction.InheritanceDemand, CertFile = "YourCertFile.cer")]
public class MainClass
{
    [PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
    public void SomeProtectedMethod () 
    {
    }
}


SecurityAction.RequestMinimum

 
using System;
using System.Net;
using System.Security.Permissions;
[assembly:SecurityPermission(SecurityAction.RequestMinimum, UnmanagedCode = true)]
class MainClass
{
    public static void Main()
    {        
    }
}


SecurityAction.RequestOptional

 

using System.Security.Permissions;
[assembly:PermissionSet(SecurityAction.RequestOptional, Name = "Internet")]
class MainClass
{
    public static void Main(){
        
    }
}


SecurityAction.RequestRefuse

 

using System.Security.Permissions;
[assembly:FileIOPermission(SecurityAction.RequestRefuse, Write = @"C:\")]
class MainClass{
   public static void Main(){
    
   
   }
}