2017-02-25 15 views
0

私はそれを行う方法が見つかりませんでした。Active Directoryからユーザーのアバターを取得するには?

using (var ctx = new PrincipalContext(ContextType.Domain, 
      _webApiServiceConfiguration.Domain, 
      _webApiServiceConfiguration.DomainAccessUserName, 
      _webApiServiceConfiguration.DomainAccessPassword)) 
{ 
    UserPrincipal userAd = UserPrincipal.FindByIdentity(ctx,user.USERID); 
} 

私はADからユーザデータを取得するためにUserPrincipalクラスを使用しています。彼の写真を得る方法はありますか?クライアントにはこのような要件があります。

答えて

2

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というプロパティもあるようです(実際にはどちらが実際に広告に表示されているかを確認する必要があります)

関連する問題