C# UserPrincipal GetUnderlyingObject:缺少属性
我正在尝试从UserPrincipal实例的GetUnderlineObject方法返回的C# UserPrincipal GetUnderlyingObject:缺少属性,c#,active-directory,principal,C#,Active Directory,Principal,我正在尝试从UserPrincipal实例的GetUnderlineObject方法返回的目录条目加载属性physicalDeliveryOfficeName: DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry; 这意味着以下语句返回false: directoryEntry.Properties.Contains("physicalDeliveryOfficeName"); 我
目录条目
加载属性physicalDeliveryOfficeName
:
DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry;
这意味着以下语句返回false:
directoryEntry.Properties.Contains("physicalDeliveryOfficeName");
我知道可以通过将名称添加到StringCollection
DirectorySearcher.PropertiesToLoad
来加载此属性,当使用所述DirectorySearcher
时
我的问题是,为什么方法
getUnderlineObject
返回的DirectoryEntry
不包含所有属性?如何在不使用DirectorySearcher的情况下加载此属性?访问DirectoryEntry的所有字段可能是一项缓慢而繁重的操作。某些字段可能不会复制到所有域控制器,因此获取这些值可能需要访问远程且访问全局编录(GC)服务器速度较慢的服务器
一旦您手头有一个DirectoryEntry,并且希望提取一个特定的值,您就可以调用该方法,并将所需属性的名称传递给它。使用刷新缓存:
UserPrincipal up = ...
using (DirectoryEntry de = up.GetUnderlyingObject() as DirectoryEntry)
{
foreach (var name in de.Properties.PropertyNames)
{
Console.WriteLine(name);
}
Console.WriteLine();
// The canonicalName attribute is operational (also called constructed).
// Active Directory does not actually save the value, but calculates it on demand. This is probably the issue. In ADSI we use the GetInfoEx
de.RefreshCache(new string[] { "canonicalName" });
var canonicalName = de.Properties["canonicalName"].Value as string;
}
objectClass
cn
sn
givenName
distinguishedName
instanceType
whenCreated
whenChanged
displayName
uSNCreated
memberOf
uSNChanged
nTSecurityDescriptor
name
objectGUID
userAccountControl
badPwdCount
codePage
countryCode
badPasswordTime
lastLogoff
lastLogon
pwdLastSet
primaryGroupID
objectSid
accountExpires
logonCount
sAMAccountName
sAMAccountType
userPrincipalName
objectCategory
dSCorePropagationData
lastLogonTimestamp
属性名称:
UserPrincipal up = ...
using (DirectoryEntry de = up.GetUnderlyingObject() as DirectoryEntry)
{
foreach (var name in de.Properties.PropertyNames)
{
Console.WriteLine(name);
}
Console.WriteLine();
// The canonicalName attribute is operational (also called constructed).
// Active Directory does not actually save the value, but calculates it on demand. This is probably the issue. In ADSI we use the GetInfoEx
de.RefreshCache(new string[] { "canonicalName" });
var canonicalName = de.Properties["canonicalName"].Value as string;
}
objectClass
cn
sn
givenName
distinguishedName
instanceType
whenCreated
whenChanged
displayName
uSNCreated
memberOf
uSNChanged
nTSecurityDescriptor
name
objectGUID
userAccountControl
badPwdCount
codePage
countryCode
badPasswordTime
lastLogoff
lastLogon
pwdLastSet
primaryGroupID
objectSid
accountExpires
logonCount
sAMAccountName
sAMAccountType
userPrincipalName
objectCategory
dSCorePropagationData
lastLogonTimestamp
canonicalName属性丢失。de.RefreshCache(新字符串[]{“canonicalName”});var canonicalName=de.Properties[“canonicalName”]。值为字符串代码>