CAS in .net
VB.NET:
Imports System.Security.Permissions
Imports System.IO
<Assembly: UIPermission(SecurityAction.RequestOptional, _
Unrestricted:=True)>
<Assembly: FileIOPermissionAttribute(SecurityAction.RequestOptional, _
Read:="C:\")>
<Assembly: FileIOPermissionAttribute(SecurityAction.RequestRefuse, _
Read:="C:\Windows\")>
Module Module1
Sub Main()
Console.WriteLine("Reading one line of the boot.ini file:")
Dim sr As StreamReader = New StreamReader("C:\boot.ini")
Console.WriteLine("First line of boot.ini: " + sr.ReadLine)
End Sub
Imports System.IO
<Assembly: UIPermission(SecurityAction.RequestOptional, _
Unrestricted:=True)>
<Assembly: FileIOPermissionAttribute(SecurityAction.RequestOptional, _
Read:="C:\")>
<Assembly: FileIOPermissionAttribute(SecurityAction.RequestRefuse, _
Read:="C:\Windows\")>
Module Module1
Sub Main()
Console.WriteLine("Reading one line of the boot.ini file:")
Dim sr As StreamReader = New StreamReader("C:\boot.ini")
Console.WriteLine("First line of boot.ini: " + sr.ReadLine)
End Sub
End Module
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Permissions;
using System.IO;
[assembly: UIPermission(SecurityAction.RequestOptional, Unrestricted = true)]
[assembly: FileIOPermissionAttribute(SecurityAction.RequestOptional, Read = @"C:\")]
[assembly: FileIOPermissionAttribute(SecurityAction.RequestRefuse, Read = @"C:\Windows\")]
namespace CASCS
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Reading one line of the boot.ini file:");
StreamReader sr = new StreamReader(@"C:\boot.ini");
Console.WriteLine("First line of boot.ini: " + sr.ReadLine());
}
}
}
using System.Linq;
using System.Text;
using System.Security.Permissions;
using System.IO;
[assembly: UIPermission(SecurityAction.RequestOptional, Unrestricted = true)]
[assembly: FileIOPermissionAttribute(SecurityAction.RequestOptional, Read = @"C:\")]
[assembly: FileIOPermissionAttribute(SecurityAction.RequestRefuse, Read = @"C:\Windows\")]
namespace CASCS
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Reading one line of the boot.ini file:");
StreamReader sr = new StreamReader(@"C:\boot.ini");
Console.WriteLine("First line of boot.ini: " + sr.ReadLine());
}
}
}
RequestMinimum contains permissions must have, RequestOptional contains permissions might use and reject all that are not listed, and RequestRefuse reject all permissions listed.