通常 AD 返回 'Objectsid' 作为byte[]
. 所以我将 AD 返回的值输入到byte[]
. 此程序对几个 AD 有效,但在一个案例中无效。在这个 AD 环境中,我得到以下异常。
例外:无法将“System.String”类型的对象转换为“System.Byte[]”类型。(System.InvalidCastException)
为了调试这个,我开始检查 AD 返回值的数据类型,但它system.string
不是byte[]
. 我打印了这个字符串,它是垃圾。然后我把这个字符串传递给SecurityIdentifier()
,我又得到了异常。
例外:值无效。参数名称:sddlForm (System.ArgumentException)
代码:
//Using System.DirectoryServices.Protocols objects
object s = objSrEc[k1].Attributes[(string)obj3.Current][0];
string x = s.GetType().FullName;
if (x.ToLower() == "system.byte[]")
{
byte[] bSID = ((byte[])s);
if (bSID != null)
{
SecurityIdentifier SID = new SecurityIdentifier(bSID, 0);
String ObjectSID = SID.Value;
}
}
else if (x.ToLower() == "system.string")
{
SecurityIdentifier SID = new SecurityIdentifier((String)s); //ssdl excception
String ObjectSID = SID.Value;
}
这是我第一次看到 AD 返回字符串数据ObjectSID
。我已经针对许多 AD 服务器运行了我的代码。我打算检查ObjectSID
AD 架构中的数据类型。
有没有人遇到过这种行为?我应该调用 Win32 apiConvertByteToStringSid()
吗?
谢谢拉梅什