开发者

Problem setting file system access rule

开发者 https://www.devze.com 2023-03-04 03:45 出处:网络
In my app on local network, any user should create a directory on shared folder using this code. test1 is the name of one开发者_C百科 of the user\'s folder for example.

In my app on local network, any user should create a directory on shared folder using this code. test1 is the name of one开发者_C百科 of the user's folder for example.

DirectoryInfo di = new DirectoryInfo(@"\\Server\Test\test1");
DirectorySecurity ds=new DirectorySecurity();
ds.SetAccessRule(new FileSystemAccessRule(Enviroment.Username,
                       FileSystemRights.FullControl, AccessControlType.Deny)); 
di.Create(ds);

Now when the admin in domain wants to read every directory from any user this error ocurred:

Attempted to perform an unauthorized operation

The code that the admin runs is:

DirectoryInfo di = new DirectoryInfo(@"\\Server\Test\test1");
DirectorySecurity ds=new DirectorySecurity();
ds.SetAccessRule(new FileSystemAccessRule(Enviroment.Username,
                       FileSystemRights.FullControl, AccessControlType.Allow)); 
di.SetAccessControl(ds);

Where is my mistake?

Thanks in advance.


Can you try like the below

        // Create a new DirectoryInfo object.
        DirectoryInfo dInfo = new DirectoryInfo(@"\\Server\Test\test1");

        // Get a DirectorySecurity object that represents the 
        // current security settings.
        DirectorySecurity dSecurity = dInfo.GetAccessControl();

        // Add the FileSystemAccessRule to the security settings. 
        dSecurity.AddAccessRule(new FileSystemAccessRule(Enviroment.Username,
                                                        FileSystemRights.FullControl, AccessControlType.Allow));

        // Set the new access settings.
        dInfo.SetAccessControl(dSecurity);
0

精彩评论

暂无评论...
验证码 换一张
取 消