2016-09-15 20 views
1

ログインしたユーザーのプロファイルイメージを取得しようとしてから、サーバーに保存しようとしています。Asp.Net Mvc 5 Azure Active Directoryサーバー上でユーザープロファイルイメージを取得して保存します。

このコードは

AuthorizationCodeReceived = async (context) => 
          { 
           var code = context.Code; 
           ClientCredential credential = new ClientCredential(clientId, appKey); 
           string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value; 
           string userObjectID = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; 
           AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID)); 
           AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
           code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId); 
           AuthenticationResult authenticationResult = await authContext.AcquireTokenSilentAsync(graphResourceId, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId)); 
           Uri servicePointUri = new Uri(graphResourceId); 
           Uri serviceRoot = new Uri(servicePointUri, tenantId); 
           ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, async() => await Task.FromResult(result.AccessToken)); 
           var res = await activeDirectoryClient.Users 
           .Where(u => u.ObjectId.Equals(userObjectID)) 
           .ExecuteAsync(); 
           IUser user = res.CurrentPage.ToList().First(); 

           var image = await user.ThumbnailPhoto.DownloadAsync(); 


          } 

は(user.ThumbnailPhoto.DownloadAsyncを待つStartup.Auth.cs

からである)エラーメッセージのための主可能な理由に基づいて

{"odata.error":{"code":"Request_ResourceNotFound","message":{"lang":"en","value":"Resource 'thumbnailPhoto' does not exist or one of its queried reference-property objects are not present."}}} 

答えて

0

このエラーをスローサムネイル写真がユーザーに設定されていないという問題があります。ユーザーのサムネイルを設定する前にコードを実行すると、この問題が再現できます。その後、コードは私のためにうまくいく。

あなたはログインして、新しい紺碧protalを設定するためのサムネイルかどうかをチェックし、下の図のように右上隅からの画像を比較することができます:私はアズールにローカルのActive Directoryと同期してから、PowerShellを介して設定 enter image description here

Azure AD接続による広告:

Set-ADUser user1 -Replace @{thumbnailPhoto=([byte[]](Get-Content "C:\Users\UserName\Desktop\me.jpg" -Encoding byte))} 
関連する問題