[英]System.Security.SecurityException: That assembly does not allow partially trusted callers
[英]Security Assembly Declaration does nothing?
我試圖使用安全聲明來限制程序集所具有的權限。 我有以下示例:
[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()中的第二行正在寫入明確設置為“只讀”權限的文件(至少我認為)。 運行此示例不會導致引發安全異常。 這是為什么?
謝謝!
大概您的應用程序正在完全信任地運行。 在完全信任狀態下,不檢查粒度CAS權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.