System.Security.AccessControl.FileSecurity sec =
File.GetAccessControl(Server.MapPath("aatish.txt"));
this.Label1.Text =
sec.GetOwner( typeof(System.Security.Principal.NTAccount) ).Value;
// retrieve the collection of access rules
AuthorizationRuleCollection auth = sec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
TableCell tc;
// loop through the rule collection and add a table row for each rule
foreach (FileSystemAccessRule r in auth)
{
TableRow tr = new TableRow();
tc = new TableCell();
tc.Text = r.AccessControlType.ToString(); // deny or allow
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.IdentityReference.Value; // who
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.InheritanceFlags.ToString();
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.IsInherited.ToString();
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.PropagationFlags.ToString();
tr.Cells.Add(tc);
tc = new TableCell();
tc.Text = r.FileSystemRights.ToString();
tr.Cells.Add(tc);
Table Table1=new Table();
Table1.Rows.Add(tr);//this table rows are not see to is not working
}
//Adding a rule to the Access Control List
//System.Security.AccessControl.FileSecurity sec1 =System.IO.File.GetAccessControl(Server.MapPath("aatish.txt"));
//sec1.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(@"Everyone",
// System.Security.AccessControl.FileSystemRights.FullControl,
//System.Security.AccessControl.AccessControlType.Allow));
//File.SetAccessControl(Server.MapPath("aatish.txt"), sec1);
//Removing a rule from the Access Control List
System.Security.AccessControl.FileSecurity sec2 = File.GetAccessControl(Server.MapPath("aatish.txt"));
sec2.RemoveAccessRule(new System.Security.AccessControl.FileSystemAccessRule(@"Everyone",
System.Security.AccessControl.FileSystemRights.FullControl,
System.Security.AccessControl.AccessControlType.Allow));
File.SetAccessControl(Server.MapPath("aatish.txt"), sec2);
Thursday, February 4, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment