UserPrincipal
クラスからユーザーの写真を取得することはできません。「1レベル深く」に移動する必要があります。基になる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から取得する」などの検索が必要な場合があります。正確に行う方法については、多くの記事があります。例えば。 this question & answerはいくつかのコードを示しています。DirectoryEntry
オブジェクトにはとthumbnailPhoto
というプロパティもあるようです(実際にはどちらが実際に広告に表示されているかを確認する必要があります)