Use of Attributes to implement security

Ddd
Posted by Ddd under C# category on | Points: 40 | Views : 1260
//FileIOPermission Attribute has been used to prevent the reading of files from C Drive


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//add these namespaces
using System.Security.Permissions;
using System.IO;
namespace ConsoleApplication20jan
{
class Class7
{
[FileIOPermission(SecurityAction.Deny,Read="C:\\")]
static void mymethod()
{

StreamReader dr = new StreamReader("c:\\windows\\abc.txt");
Console.WriteLine(dr.ReadToEnd());
dr.Close();
}
static void Main()
{
mymethod();

}
}
}

Comments or Responses

Login to post response