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






<%@ Page Language="VB" %>
<%@ 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 Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim sec As System.Security.AccessControl.FileSecurity = System.IO.File.GetAccessControl(Server.MapPath("TextFile.txt"))
        
        Me.Label1.Text = sec.GetOwner(System.Type.GetType("System.Security.Principal.NTAccount")).Value
      
        Dim auth As AuthorizationRuleCollection = sec.GetAccessRules(True, True, System.Type.GetType("System.Security.Principal.NTAccount"))

        Dim tc As TableCell
        For Each r As FileSystemAccessRule In auth
        
            Dim tr As 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)
        Next
    End Sub

</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)