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。