【发布时间】:2011-08-12 06:20:14
【问题描述】:
我有以下方法来检查当前用户对给定网络位置的写入权限
DirectorySecurity shareSecurity = new DirectoryInfo(this.GetFileServerRootPath).GetAccessControl();
foreach (FileSystemAccessRule fsRule in shareSecurity.GetAccessRules(true, true, typeof(NTAccount)))
{
// check write permission for current user
if (AccessControlType.Allow == fsRule.AccessControlType &&
FileSystemRights.Write == (fsRule.FileSystemRights & FileSystemRights.Write))
{
if (null != fsRule.IdentityReference &&
fsRule.IdentityReference.Value == WindowsIdentity.GetCurrent().Name)
{
return true;
}
}
}
return false;
但问题是当授予用户组文件夹权限时,上述方法失败。
我不想通过写文件来检查权限并决定写访问权限。
有没有办法在IdentityReference.Value 中找到当前用户?或解决此问题的建议?
【问题讨论】:
-
我猜它返回 false 由于这部分:
fsRule.IdentityReference.Value == WindowsIdentity.GetCurrent().Name -
是的,当
fsRule.IdentityReference.Value是一个组时,我需要检查用户是否是该组的成员
标签: c# permissions c#-2.0