我试图为特定用户在UNC路径上提供NTFS权限,但我发现UNC路径不同会导致不同的行为。以下是我用于授予权限的代码(来自MSDN),以及每种情况下的结果:
static void GiveNTFSPermissions(string folderPath,
string ntAccountName,
FileSystemRights accessRights)
{
DirectorySecurity dirSecurity = Directory.GetAccessControl(folderPath);
FileSystemAccessRule newAccessRule =
new FileSystemAccessRule(
ntAccountName,
accessRights,
AccessControlType.Allow);
dirSecurity.AddAccessRule(newAccessRule);
Directory.SetAccessControl(folderPath, dirSecurity);
}
假设我在本地机器上有一个名为“RootShare”的共享文件夹,并且里面还有一个名为“InsideRootShare”的文件夹。 场景1: 当我调用以下命令时,
GiveNTFSPermissions(@"\\sri-devpc\RootShare",
@"domain\username",
FileSystemRights.Write);
继承权限在共享路径上丢失,
场景2:当我调用时,
GiveNTFSPermissions(@"\\sri-devpc\RootShare\InsideRootShare",
@"domain\username",
FileSystemRights.Write);
继承权限保持完好无损。
我尝试了不同的FileSystemAccessRule
构造函数,但没有运气。
这种行为背后的原因是什么,有没有解决方法?