C# 使用NTAccount的GetAccessControl错误
上面的代码块导致了我的问题。执行WinPrincipal.IsInRolerule.IdentityReference.Value时,会发生以下异常: 主域和受信任域之间的信任关系失败 我对使用身份、原则等方面非常陌生,所以我不知道问题出在哪里。我想是用了NTAccountC# 使用NTAccount的GetAccessControl错误,c#,.net,security,filesystems,C#,.net,Security,Filesystems,上面的代码块导致了我的问题。执行WinPrincipal.IsInRolerule.IdentityReference.Value时,会发生以下异常: 主域和受信任域之间的信任关系失败 我对使用身份、原则等方面非常陌生,所以我不知道问题出在哪里。我想是用了NTAccount 谢谢我可以尝试通过建议您使用SecurityIdentifier来解决您的问题,但这里还有许多其他问题,即使这些问题得到解决,仍然会阻碍节目的进行。我说的不是诸如使用FileInfo而不是File之类的低效,而是您试图用来解
谢谢我可以尝试通过建议您使用SecurityIdentifier来解决您的问题,但这里还有许多其他问题,即使这些问题得到解决,仍然会阻碍节目的进行。我说的不是诸如使用FileInfo而不是File之类的低效,而是您试图用来解释DACL的基本逻辑 看看:
private bool HasRights(FileSystemRights fileSystemRights_, string fileName_, bool isFile_)
{
bool hasRights = false;
WindowsIdentity WinIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
WindowsPrincipal WinPrincipal = new WindowsPrincipal(WinIdentity);
AuthorizationRuleCollection arc = null;
if (isFile_)
{
FileInfo fi = new FileInfo(@fileName_);
arc = fi.GetAccessControl().GetAccessRules(true, true, typeof(NTAccount));
}
else
{
DirectoryInfo di = new DirectoryInfo(@fileName_);
arc = di.GetAccessControl().GetAccessRules(true, true, typeof(NTAccount));
}
foreach (FileSystemAccessRule rule in arc)
{
if (WinPrincipal.IsInRole(rule.IdentityReference.Value))
{
if (((int)rule.FileSystemRights & (int)fileSystemRights_) > 0)
{
if (rule.AccessControlType == AccessControlType.Allow)
hasRights = true;
else if (rule.AccessControlType == AccessControlType.Deny)
{
hasRights = false;
break;
}
}
}
}
return hasRights;
}