I am trying to restrict the permissions my assembly has using Security Declarations. I have the follow example:
[assembly: UIPermission(SecurityAction.RequestOptional,Unrestricted = true)]
[assembly: FileIOPermission(SecurityAction.RequestOptional, Read = @"C:\Hello.txt")]
class Program
{
static void Main(string[] args)
{
// Create a file
TextWriter tw = new StreamWriter(@"C:\Hello.txt");
tw.WriteLine("Hello, world!");
tw.Close();
// Display the text of the file
TextReader tr = new StreamReader(@"C:\Hello.txt");
Console.WriteLine(tr.ReadToEnd());
tr.Close();
Console.ReadLine();
}
}
The second line in the main() is writing to the file that explicitly set to 'read only' permissions (at least I thought). Running this example does not result in a security exception thrown. Why is that?
Thanks!
Presumably your app is running with full-trust. In full trust granular CAS permissions are not checked .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.