嵌入Power Bi Report Promise未定义为powerbi.js

我创建了一个power bi报告。 我想将此报告嵌入我的MVC网站。 这是我的代码: –

private static readonly string ClientID = ConfigurationManager.AppSettings["ClientID"]; private static readonly string ClientSecret = ConfigurationManager.AppSettings["ClientSecret"]; private static readonly string RedirectUrl = ConfigurationManager.AppSettings["RedirectUrl"]; private static readonly string AADAuthorityUri = ConfigurationManager.AppSettings["AADAuthorityUri"]; private static readonly string PowerBiAPI = ConfigurationManager.AppSettings["PowerBiAPI"]; private static readonly string PowerBiDataset = ConfigurationManager.AppSettings["PowerBiDataset"]; private static readonly string baseUri = PowerBiDataset; private static string accessToken = string.Empty; public string GetAccessToken(string authorizationCode, string clientID, string clientSecret, string redirectUri) { TokenCache TC = new TokenCache(); string authority = AADAuthorityUri; AuthenticationContext AC = new AuthenticationContext(authority, TC); ClientCredential cc = new ClientCredential(clientID, clientSecret); return AC.AcquireTokenByAuthorizationCodeAsync( authorizationCode, new Uri(redirectUri), cc).Result.AccessToken; } public void GetAuthorizationCode() { var @params = new NameValueCollection { {"response_type", "code"}, {"client_id", ClientID}, {"resource", PowerBiAPI}, { "redirect_uri", RedirectUrl} }; var queryString = HttpUtility.ParseQueryString(string.Empty); queryString.Add(@params); Response.Redirect(String.Format(AADAuthorityUri + "?{0}", queryString)); } public ActionResult Index() { if (Request.QueryString["code"] != null) { Session["AccessToken"] = GetAccessToken( HttpContext.Request["code"], ClientID, ClientSecret, RedirectUrl); } if (Session["AccessToken"] != null) { accessToken = Session["AccessToken"].ToString(); System.Net.WebRequest request = System.Net.WebRequest.Create( String.Format("{0}/Reports", baseUri)) as System.Net.HttpWebRequest; request.Method = "GET"; request.ContentLength = 0; request.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken)); using (var response = request.GetResponse() as System.Net.HttpWebResponse) { using (var reader = new System.IO.StreamReader(response.GetResponseStream())) { PBIReports Reports = JsonConvert.DeserializeObject(reader.ReadToEnd()); if (Reports.value.Length > 0) { PBIReport report = Reports.value[13]; return View(report); } } } } GetAuthorizationCode(); return View(); } 

在重定向到“this”时,它会进入power bi登录页面,在我登录后重定向回到此页面(因为主页和重定向URL相同)。 获取所有报告数据后,一段时间后出现一条错误消息,说明Unhandled exception at line 5153, column 11 in http://localhost:34244/Scripts/powerbi.js 0x800a1391 - JavaScript runtime error: 'Promise' is undefined

之后它说

  Exception was thrown at line 1236, column 335 in https://app.powerbi.com/13.0.1781.272/scripts/powerbiportal.dependencies.externals.bundle.min.js 0x80070005 - JavaScript runtime error: Access is denied. If there is a handler for this exception, the program may be safely continued. Exception was thrown at line 42, column 17057 in https://app.powerbi.com/13.0.1781.272/scripts/powerbiportal.common.bundle.min.js 0x80070005 - JavaScript runtime error: Access is denied. If there is a handler for this exception, the program may be safely continued. 

然后再次开始再次显示第一条错误消息。

这是我的index.cshtml

 @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_ColumnsOne.cshtml"; }   window.onload = function () { var accessToken = "@Session["AccessToken"].ToString()"; if (!accessToken || accessToken == "") { return; } var embedUrl = "@Model.embedUrl"; var reportId = "@Model.id"; var config = { type: 'report', accessToken: accessToken, embedUrl: embedUrl, id: reportId, settings: { filterPaneEnabled: false, navContentPaneEnabled: false } }; const filter = { $schema: "http://powerbi.com/product/schema#basic", target: { table: "Query1", column: "SchoolID" }, operator: "In", values: ["10"] }; var reportContainer = document.getElementById('reportContainer'); var report = powerbi.embed(reportContainer, config); report.on("loaded", function () { var logView = document.getElementById('logView'); logView.innerHTML = logView.innerHTML + "Loaded
"; report.off("loaded"); }); report.on("rendered", function () { var logView = document.getElementById('logView'); logView.innerHTML = logView.innerHTML + "Rendered
"; report.off("rendered"); }); report.setFilters([filter]) .then(function (result) { Log.log(result); }) .catch(function (errors) { Log.log(errors); }); };

IE尚不支持Promise。 您可以通过包含外部库来启用支持。 请参阅Microsoft关于Power BI的评论 – 支持IE8和Promises?

我和IE11有同样的问题,建议有效! 希望它也能帮到你。