Class1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
源码类别:

C#编程

开发平台:

Others

  1. using System; using System.IO; using System.Security; using System.Security.Permissions;
  2. namespace Wrox.ProCSharp.Security {    class SecurityApp5    {       static void Main(string[] args)
  3.       {          CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.Append,@"c:audit.txt");
  4.          permission.Deny();
  5.          AuditClass.Save("some data to audit");
  6.          CodeAccessPermission.RevertDeny();
  7.       }    }    class AuditClass    {       public static void Save(string value)       {          try          {             FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Append,@"c:audit.txt");             permission.Assert();             FileStream stream = new FileStream(@"c:audit.txt",FileMode.Append, FileAccess.Write);             // code to write to audit file here...             CodeAccessPermission.RevertAssert();             Console.WriteLine("Data written to audit file");          }          catch          {             Console.WriteLine("Failed to write data to audit file");          }       }    } }