Access Control List information (C#) : Access Control « File Directory « ASP.NET Tutorial






<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Security.AccessControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Security.AccessControl.FileSecurity sec = File.GetAccessControl(Server.MapPath("Data.txt"));
        
        this.Label1.Text = sec.GetOwner( typeof(System.Security.Principal.NTAccount) ).Value;
      
        AuthorizationRuleCollection auth = sec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

        TableCell tc;
        foreach (FileSystemAccessRule r in auth)
        {
            TableRow tr = new TableRow();
            
            tc = new TableCell();
            tc.Text = r.AccessControlType.ToString(); 
            tr.Cells.Add(tc);

            tc = new TableCell();
            tc.Text = r.IdentityReference.Value; 
            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);

            Table1.Rows.Add(tr);
        }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <b>File Owner:</b>
              <asp:Label ID="Label1" runat="server" Text="Label" />        
        
        Access Rules:<br />
        <asp:Table ID="Table1" runat="server" CellPadding="2" GridLines="Both">
            <asp:TableRow>
                <asp:TableHeaderCell>Control Type</asp:TableHeaderCell>
                <asp:TableHeaderCell>Identity</asp:TableHeaderCell>
                <asp:TableHeaderCell>Inheritance Flags</asp:TableHeaderCell>
                <asp:TableHeaderCell>Is Inherited</asp:TableHeaderCell>
                <asp:TableHeaderCell>Propagation Flags</asp:TableHeaderCell>     
                <asp:TableHeaderCell>File System Rights</asp:TableHeaderCell>
            </asp:TableRow>
        </asp:Table>
                
    
    </div>
    </form>
</body>
</html>








10.10.Access Control
10.10.1.Access Control List information (C#)
10.10.2.Access Control List information (VB)
10.10.3.Adding a rule to the Access Control List (C#)
10.10.4.Adding a rule to the Access Control List (VB)
10.10.5.Removing the rule from the Access Control List (C#)
10.10.6.Removing the rule from the Access Control List (VB)