我们将.Net 4.0类库移植到.Net Core 1.1,并遇到了对.Net core CLR中文件安全性和权限的非常有限支持的问题。我们试图按如下所示设置对文件的访问控制权限,并且FileInfo似乎不再具有任何SetAccessControl或GetAccessControl。
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
Run Code Online (Sandbox Code Playgroud)
目标只是向文件的当前所有者添加执行权,我们非常感谢您的帮助。