执行下面的代码,看看是所有属性的提供您的广告。还有就是你可能有一个变化拼错的关键或钥匙不在您的广告存在的所有属性
DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
try
{
foreach (string property in resEnt.Properties.PropertyNames)
{
string value = resEnt.Properties[property][0].ToString();
Console.WriteLine(property + ":" + value);
}
}
catch (Exception)
{ }
}
名单在我的Windows Server 2008 R2 AD
objectClass=top;person;organizationalPerson;user
cn=x1
sn=LastName
c=PL
l=City
st=State
title=Job title
description=Description
postalCode=Zip
postOfficeBox=POBox
physicalDeliveryOfficeName=Office
telephoneNumber=123456779
givenName=FirstName
distinguishedName=CN=x1,CN=Users,DC=helpdesk,DC=wat,DC=edu
instanceType=4
whenCreated=2012-11-27 21:37:37
whenChanged=2012-12-11 21:33:51
displayName=DisplayName
uSNCreated=System.__ComObject
uSNChanged=System.__ComObject
co=Poland
department=Department
company=Company
streetAddress=Street
name=x1
objectGUID=System.Byte[]
userAccountControl=66048
badPwdCount=0
codePage=0
countryCode=616
badPasswordTime=System.__ComObject
lastLogoff=System.__ComObject
lastLogon=System.__ComObject
pwdLastSet=System.__ComObject
primaryGroupID=513
objectSid=System.Byte[]
accountExpires=System.__ComObject
logonCount=1
sAMAccountName=x1
sAMAccountType=805306368
[email protected]
objectCategory=CN=Person,CN=Schema,CN=Configuration,DC=helpdesk,DC=wat,DC=edu
dSCorePropagationData=1601-01-01 00:00:00
lastLogonTimestamp=System.__ComObject
[email protected]
homePhone=1236456654654659
mobile=800800800
nTSecurityDescriptor=System.__ComObject
来源
2015-04-24 08:03:54
Rad
调试它。当你得到一些用户检查UserPrincipal的所有属性。如果有任何属性被填入像GivenName或其他东西 - 比它被读取,所以如果某些属性为空 - 那么它真的是nul – MajkeloDev