我正在尝试使用安全声明来限制我的程序集拥有的权限。我有下面的例子:
 [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()中的第二行是写入显式设置为“只读”权限的文件(至少我认为是这样)。运行此示例不会导致引发安全异常。为什么会这样呢?
谢谢!
发布于 2010-11-18 11:36:45
想必你的应用程序是以完全信任模式运行的。在完全信任中,不检查细粒度CAS权限。
https://stackoverflow.com/questions/4211449
复制相似问题