问题 如何在.NET Core中修改文件访问控制


我正在尝试更改.NET Core中文件的权限。 然而,似乎 的FileInfo 没有 SetAccessControl 了。

// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(FileName);

// Get a FileSecurity object that represents the 
// current security settings.
FileSecurity fSecurity = fInfo.GetAccessControl();

// Add the FileSystemAccessRule to the security settings. 
fSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                                                Rights,
                                                ControlType));

// Set the new access settings.
fInfo.SetAccessControl(fSecurity);

目标只是将执行权添加到文件的当前所有者(不是Windows或Unix特定功能)。

有关如何在.NET Core上执行此操作的任何线索?


1431
2017-11-06 13:41


起源

你期望在具有不同访问控制系统的Unix上发生什么?或者这是一个仅限Windows的.Net Core应用程序? - svick
@svick我希望像普通子集一样。我将在Mono上检查已完成的工作(如果已完成)。 - Fab


答案:


FileSecurity 班级现在是其中的一部分 System.IO.FileSystem.AccessControl .NET Core的软件包。不再是了 File.GetAccessControl 方法,所以你需要实现 FileSecurity 实例自己。


9
2017-12-07 14:21



另外,创建新的.NET Core 2.0库不会包含此程序集。你将不得不添加 System.IO.FileSystem.AccessControl 作为NuGet包。 - Scyssion
@Scyssion是的,我的评论说。 - Patrik Svensson