我正在使用.Net Core 2.0和Novell.Directory.Ldap.NETStandard 2.3.8并使用以下代码从Active Directory获取用户资源属性。 我正在获取除objectGUID之外的所有属性的值,其中我获得了一些垃圾值。
LdapEntry userEntry = ldapConn.Read(dn);
LdapAttribute uid = userEntry?.getAttribute("objectGUID");
输出:
{LdapAttribute: {type='objectGUID', value='�� ���E�1���Ѕv'}}
如果我使用LDAP作为后端实体,则没有问题。
当我使用下面的代码来获取Guid时,我得到了以下错误。
新Guid(SupportClass.ToByteArray(userEntry.getAttribute("objectGuid").ByteValue)).ToString()
错误:
'new Guid(SupportClass.ToByteArray(userEntry.getAttribute("objectGuid").ByteValue)).ToString()' threw an exception of type 'System.ArgumentException'
"Byte array for GUID must be exactly 16 bytes long.\r\nParameter name: b"
答案 0 :(得分:0)
这是一种GUID格式,因此您可以使用字符串值,并且应该将字节值转换为guid。请参阅:
var bytes = (byte[])(nextEntry.getAttribute("objectGUID").ByteValue as object);
var guid = new Guid(bytes);
希望这会有所帮助! enter image description here