Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用NTAccount的GetAccessControl错误_C#_.net_Security_Filesystems - Fatal编程技术网

C# 使用NTAccount的GetAccessControl错误

C# 使用NTAccount的GetAccessControl错误,c#,.net,security,filesystems,C#,.net,Security,Filesystems,上面的代码块导致了我的问题。执行WinPrincipal.IsInRolerule.IdentityReference.Value时,会发生以下异常: 主域和受信任域之间的信任关系失败 我对使用身份、原则等方面非常陌生,所以我不知道问题出在哪里。我想是用了NTAccount 谢谢我可以尝试通过建议您使用SecurityIdentifier来解决您的问题,但这里还有许多其他问题,即使这些问题得到解决,仍然会阻碍节目的进行。我说的不是诸如使用FileInfo而不是File之类的低效,而是您试图用来解

上面的代码块导致了我的问题。执行WinPrincipal.IsInRolerule.IdentityReference.Value时,会发生以下异常:

主域和受信任域之间的信任关系失败

我对使用身份、原则等方面非常陌生,所以我不知道问题出在哪里。我想是用了NTAccount


谢谢

我可以尝试通过建议您使用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;
    }