Class1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
- using System;
- using System.IO;
- using System.Security;
- using System.Security.Permissions;
- namespace Wrox.ProCSharp.Security
- {
- class SecurityApp4
- {
- static void Main(string[] args)
- {
- CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess,@"c:");
- permission.Deny();
- UntrustworthyClass.Method();
- CodeAccessPermission.RevertDeny();
- }
- }
- class UntrustworthyClass
- {
- public static void Method()
- {
- try
- {
- StreamReader din = File.OpenText(@"c:animals.txt");
}
- catch
- {
- Console.WriteLine("Failed to open file");
- }
- }
- }
- }