Folder level permissions using asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bharathreddy
    New Member
    • Aug 2006
    • 116

    #1

    Folder level permissions using asp.net

    Hi,
    I am developing an application in which a user can create folders and set the permission to the specific users. When the folder is screated at the first time no user should have permissions on the folder. But i found that all the users are able to access the folder.
    How can I change the folder permissions using asp.net code. Thanks in advance.


    Thanks & Regards
    Bharath Reddy VasiReddy
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    This is some code that I was playing with, it is in vb.net but you might be able to convert it

    it is not my tidiest code but it basically adds the current user to the ACL for a folder and sets ' administrators ' as the owner, I had some problems setting the owner before I gave permissions



    Code:
    Imports System.IO
    Imports System.Security.Permissions
    Imports System.Security.Principal
    
    
    Public Class Form1
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim self = System.Security.Principal.WindowsIdentity.GetCurrent()
            Dim Rulz = New System.Security.AccessControl.FileSystemAccessRule(self.Name, System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow) ' create ACL 
            Dim mydir As New DirectoryInfo("c:\test")
            Dim vals As System.Security.AccessControl.FileSystemAccessRule
            Dim x = mydir.GetAccessControl()
            Dim permlists = x.GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount))
            Dim nt As New System.Security.Principal.NTAccount("", "Administrators")
            Dim gr As System.Security.Principal.IdentityReference = nt
    
            Dim tempown = x.GetOwner(GetType(System.Security.Principal.NTAccount)) ' check current owner
            MsgBox(tempown.Value)
    
            x.AddAccessRule(Rulz)  ' add ACL to X
    
            mydir.SetAccessControl(x) ' set access control oin folder using x
    
            x.SetOwner(nt) ' set owner for folder to administrators
    
            mydir.SetAccessControl(x) ' set access control oin folder using x
    
            Dim num As Integer = 0
    
            For Each vals In permlists ' check current permissions
    
                ListBox1.Items.Add(vals.IdentityReference.Value & " - " & vals.FileSystemRights.ToString)
    
                 num += 1
    
            Next
    
    
    
        End Sub
    End Class

    Comment

    Working...