设置文件系统访问规则时出现问题

发布于 2024-11-06 02:55:27 字数 801 浏览 0 评论 0原文

在我的本地网络上的应用程序中,任何用户都应该使用此代码在共享文件夹上创建一个目录。例如,test1 是用户文件夹之一的名称。

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

现在,当域中的管理员想要读取任何用户的每个目录时,就会发生此错误:

试图执行未经授权的操作

管理员运行的代码是:

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

我的错误在哪里?
提前致谢。

In my app on local network, any user should create a directory on shared folder using this code. test1 is the name of one 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2024-11-13 02:55:27

你可以尝试像下面这样吗

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文