2017-04-25 3 views
0

IISでプロジェクトを展開すると次のエラーが発生し、Visual Studioから実行したときに正常に動作しています。 AccessToken電力BI:System.InvalidOperationException:アプリケーションが実行されていないときにモーダルダイアログボックスまたはフォームを表示

return authContext.AcquireToken(this.PowerBiAPI, this.ClientID, new Uri(this.RedirectUrl)).AccessToken; 

エラーを取得する方法を下回る呼び出すときに

エラーは次のとおりです。this.ClientIDアプリケーションタイプのために生成される。ここ

System.InvalidOperationException: 
Showing a modal dialog box or form when the application is not running in 
UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly 
style to display a notification from a service application. 
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.RunAsyncTask[T](Task`1 task) 
at DSLUI.Controllers.BusinessLogic.ReportService.GetAccessToken() 

:ネイティブ

ウェブ:https://dev.powerbi.com/apps

上記のエラーについてご意見がありましたら、私たちはlpです。

答えて

0

私はApp type Nativeを使用しているため、この問題の原因となっているサーバー側でAADポップアップが発生しています。

次に、私はそれをApp Typeに変更してWebアプリケーションに送信し、以下のコードを使用してアクセストークンを取得すると、問題は解決しました。

public async Task<string> GetAccessToken() 
    { 
     try 
     { 
      var password = Utility.Decrypt(this.PWBI_Psw); 

      var content = new FormUrlEncodedContent(new[] 
       { 
       new KeyValuePair<string, string>("grant_type", "password"), 
       new KeyValuePair<string, string>("scope", "openid"), 
       new KeyValuePair<string, string>("username", this.PWBI_User), 
       new KeyValuePair<string, string>("password", password), 
       new KeyValuePair<string, string>("client_id", this.ClientID), 
       new KeyValuePair<string, string>("client_secret", this.ClientSecretKey), 
       new KeyValuePair<string, string>("resource", this.PowerBiAPI) 
       }); 

      string tokenEndpointUri = string.Format(this.TokenEndpointUri, this.TenantID); 
      using (var client = new HttpClient()) 
      { 
       HttpResponseMessage res = client.PostAsync(tokenEndpointUri, content).Result; 

       string json = await res.Content.ReadAsStringAsync(); 

       var obj = JObject.Parse(json); 
       var AccessToken = (string)obj["access_token"]; 

       return AccessToken; 
      } 
     } 
     catch (Exception ex) 
     { 

      throw ex; 
     } 
    } 
+0

解決策を返信して投稿してくれてありがとう。 –

関連する問題