Hi,
In this code, I'd like the ReadFileSystem method to be forbidden to Assert a permission on the filesystem.
I expected this will throw at fileIo.Assert(), but it doesn't. Why?
using System.Security.Permissions;
static void Main(string[] args)
{
var fileIo = new FileIOPermission(PermissionState.Unrestricted);
var secuPerm = new SecurityPermission(SecurityPermissionFlag.Assertion);
PermissionSet set = new PermissionSet(PermissionState.Unrestricted);
set.AddPermission(fileIo);
set.AddPermission(secuPerm);
set.Deny();
ReadFileSystem();
Console.Read();
}
private static void ReadFileSystem()
{
var fileIo = newFileIOPermission(PermissionState.Unrestricted);
fileIo.Assert();
DirectoryInfo dir = new DirectoryInfo("C:/");
dir.GetDirectories();
}
Update
Great link here on CAS : http://blogs.msdn.com/shawnfa/archive/2004/08/25/220458.aspx