UserPrincipal.FindByIdentity() always returns null

徘徊边缘 提交于 2019-12-01 06:08:15

By using IdentityType.Name, you're telling it that the value you're passing is the name of the account (which is the cn attribute). If you want to match by username (the sAMAccountName atrribute), you'll need to pass IdentityType.SamAccountName.


Old answer: But you seem to be sending it the email address. So that will indeed always return nothing.

AD does not consider an email address to be a unique identifier, so you cannot use FindByIdentity with an email address.

Here is an example on how to search by email address: http://doogalbellend.blogspot.ca/2012/03/finding-userprincipal-for-email-address.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!