![](/img/trans.png)
[英]How to get list of Users from Active Directory by attributes such as Department
[英]How to get users avatar from Active Directory?
我還沒有找到任何辦法。
using (var ctx = new PrincipalContext(ContextType.Domain,
_webApiServiceConfiguration.Domain,
_webApiServiceConfiguration.DomainAccessUserName,
_webApiServiceConfiguration.DomainAccessPassword))
{
UserPrincipal userAd = UserPrincipal.FindByIdentity(ctx,user.USERID);
}
我正在使用UserPrincipal
類從AD獲取用戶數據。 有沒有辦法得到他的照片? 客戶有這樣的要求。
您無法從UserPrincipal
類中獲取用戶的照片-您必須“更深入”,例如獲取基礎DirectoryEntry
對象,然后找出哪個AD屬性正在保存您的圖片。
using (var ctx = new PrincipalContext(ContextType.Domain,
_webApiServiceConfiguration.Domain,
_webApiServiceConfiguration.DomainAccessUserName,
_webApiServiceConfiguration.DomainAccessPassword))
{
UserPrincipal userAd = UserPrincipal.FindByIdentity(ctx,user.USERID);
// if not null, get the underlying DirectoryEntry
if (userAd != null)
{
DirectoryEntry de = userAd.GetUnderlyingObject() as DirectoryEntry;
// if de is not null
if (de != null)
{
// get the property in question - possibly the "photo" property
if(de.Properties["photo"] != null)
{
// unlike a database column, an AD property can contain *multiple* values....
}
}
}
另外:那些“二進制”屬性通常是用AD編碼的,因此不要期望在該屬性中找到照片的確切二進制字節-您可能需要進行一些轉換或其他操作……
您可能要搜索“從Active Directory獲取照片”之類的東西-關於如何執行此操作的文章很多。 例如, 此問題和答案顯示了一些代碼-並且DirectoryEntry
對象上似乎也有jpegPhoto
和thumbnailPhoto
屬性。...(因此,您必須檢查廣告中確實填充了哪個)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.