- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么 Principal.IsMemberOf(GroupPrincipal)
( MSDN ) 在以下测试中为 Domain Computers
组返回假阴性?
[TestMethod]
public void DomainComputerTest()
{
var distinguishedName = "CN=MyMachine,DC=SomeDomain,DC=local";
using( var pc = new PrincipalContext( ContextType.Domain, "SomeDomain.local", "UserName", "Password" ) )
using( var computer = ComputerPrincipal.FindByIdentity( pc, IdentityType.DistinguishedName, distinguishedName ) )
{
Assert.IsNotNull( computer );
// Get the groups for the computer.
var groups = computer.GetGroups().Cast<GroupPrincipal>();
foreach( var group in groups )
{
// Immediately turn around and test that the computer is a member of the groups it returned.
Assert.IsTrue( computer.IsMemberOf( group ), "Computer is not member of group {0}", group.Name );
}
}
}
结果消息:Assert.IsTrue 失败。计算机不是“域计算机”组的成员
该计算机确实是“域计算机”组的成员,“GetGroups()”方法正确返回了该组。事实上,如果您尝试将计算机添加到组中,则会抛出 PrincipalExistsException。
我可以重现与用户和“域用户”组完全相同的行为。这是因为这些团体是主要团体吗?是因为这些是“默认”组吗?
编辑添加:我们正在使用 .NET 4.5.1。
最佳答案
这似乎是一个一直存在的问题。
我发现的与您相同的问题的每个问题都没有得到解答。我找不到任何说这是作为错误提交的内容,但似乎自 .NET 3.5 以来就存在了。
我试图让您的示例返回 true
(当然将信息更改为我的工作域)。不管怎样,它返回了 false
。反编译 dotPeek 中的 Principal
类仅产生推测。完成并设置 Visual Studio 以允许单步执行 .NET 框架代码是一个失败,因为它不会单步执行必要的方法。我可以进入其他 .NET 框架代码,但不能进入 Principal
。不确定这是否与使用 SecurityCriticalAttribute
标记的方法有关。很想确认这一点。
我对您的建议是将此作为错误归档,同时采用不同的途径来确定计算机是否是成员。在我的测试中,group.Members
确实包含计算机。
我在运行 .NET 3.5、4.0、4.5、4.5.1 时遇到了同样的问题
以下是一些引用资料:
解决方法 -- GroupPrincipal.IsMemberOf always returns false
A 2010 MSDN Blog entry with a comment that had the same issue as you.
注意:我通常不会这样回答,但因为我发现的关于这个问题的每个问题都有 0 个答案或解决方法,我认为这对 future 的读者实际看到某种“回答”这个问题。
关于c# - 为什么 Principal.IsMemberOf() 对某些组返回假阴性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26981922/
我将所有正样本的大小调整为相同的大小,因此负样本的大小也应与正样本的大小相同。 最佳答案 通常,通过对象检测,您可以在图像上滑动固定大小的搜索窗口,从而产生特征响应。然后,分类器将响应与经过训练的模型
我是一名优秀的程序员,十分优秀!