Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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# WindowsIdentity.Contains()未给出正确的结果_C#_Winforms_Authentication_Active Directory - Fatal编程技术网

C# WindowsIdentity.Contains()未给出正确的结果

C# WindowsIdentity.Contains()未给出正确的结果,c#,winforms,authentication,active-directory,C#,Winforms,Authentication,Active Directory,我正在使用WindowsIdentity对AD进行身份验证,以获取用户所属的组。但是,无论我在Contains函数参数中输入了什么,运行下面的代码总是返回true WindowsIdentity _user = WindowsIdentity.GetCurrent(); IdentityReferenceCollection _identityReferenceCollection = _user.Groups.Translate(typeof(NTAccount)); if (_id

我正在使用
WindowsIdentity
对AD进行身份验证,以获取用户所属的组。但是,无论我在Contains函数参数中输入了什么,运行下面的代码总是返回true

WindowsIdentity _user = WindowsIdentity.GetCurrent();
IdentityReferenceCollection _identityReferenceCollection = 
    _user.Groups.Translate(typeof(NTAccount));
if (_identityReferenceCollection != null && 
   (_user.Groups != null && _identityReferenceCollection.ToString().Contains("blah")))
{
    MnuDataEntry.Enabled = false;
}

我是否错误地使用了contains函数?我已经查看了调试器,没有名为“blah”的组。

您找到
\u identityReferenceCollection.ToString()
返回的内容了吗?问得好!“System.Security.Principal.IdentityReferenceCollection”那么我应该遍历它吗?我会遍历它,是的。或者尝试
\u identityReferenceCollection.Any(x=>…)
或其他方法。可能需要将
Cast()
粘贴在
Any()
前面,我不知道在这种情况下
t
会是什么,所以。。。从foreach开始Ah,它实现了。你在做生意。
\u identityReferenceCollection.ToString()
sweet jebus。