我正在尝试使用安全声明限制程序集所具有的权限。我有以下例子:
[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();
}
}
main()中的第二行是写入明确设置为“只读”权限的文件(至少我认为)。运行此示例不会导致抛出安全性异常。那是为什么?
谢谢!
答案 0 :(得分:0)
据推测,您的应用程序正在以完全信任的方式运行。在完全信任状态下,不检查的。。。