【问题标题】:Power BI : System.InvalidOperationException: Showing a modal dialog box or form when the application is not running inPower BI:System.InvalidOperationException:当应用程序未运行时显示模式对话框或表单
【发布时间】:2017-04-25 11:21:03
【问题描述】:

我们在 IIS 中部署项目时遇到以下错误,从 Visual Studio 运行时它工作正常。

调用以下方法获取AccessToken时出错

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

错误是:

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() 

这里为 App Type: Native 生成​​ this.ClientID

网络:https://dev.powerbi.com/apps

如果有人对上述错误有任何想法,请帮助我们。

【问题讨论】:

    标签: asp.net-mvc azure iis powerbi powerbi-embedded


    【解决方案1】:

    由于我使用的是应用类型 Native,AAD 弹出窗口在服务器端出现导致此问题。

    然后我将其更改为应用程序类型为 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;
            }
        }
    

    【讨论】:

    • 感谢您返回并发布您的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多