我创建了一个 power bi 报告.我想将此报告嵌入到我的 MVC 站点.这是我的代码:-
私有静态只读字符串 ClientID = ConfigurationManager.AppSettings["ClientID"];私有静态只读字符串 ClientSecret = ConfigurationManager.AppSettings["ClientSecret"];私有静态只读字符串 RedirectUrl = ConfigurationManager.AppSettings["RedirectUrl"];私有静态只读字符串 AADAuthorityUri = ConfigurationManager.AppSettings["AADAuthorityUri"];私有静态只读字符串 PowerBiAPI = ConfigurationManager.AppSettings["PowerBiAPI"];私有静态只读字符串 PowerBiDataset = ConfigurationManager.AppSettings["PowerBiDataset"];私有静态只读字符串 baseUri = PowerBiDataset;私有静态字符串 accessToken = string.Empty;公共字符串GetAccessToken(字符串authorizationCode,字符串clientID,字符串clientSecret,字符串redirectUri){令牌缓存 TC = 新令牌缓存();字符串权限 = AADAuthorityUri;AuthenticationContext AC = new AuthenticationContext(authority, TC);ClientCredential cc = new ClientCredential(clientID, clientSecret);返回 AC.AcquireTokenByAuthorizationCodeAsync(授权码,新的 Uri(redirectUri), cc).Result.AccessToken;}公共无效GetAuthorizationCode(){var @params = 新的 NameValueCollection{{"response_type", "code"},{"client_id", ClientID},{"资源", PowerBiAPI},{ "redirect_uri", RedirectUrl}};var queryString = HttpUtility.ParseQueryString(string.Empty);queryString.Add(@params);Response.Redirect(String.Format(AADAuthorityUri + "?{0}", queryString));}公共行动结果索引(){if (Request.QueryString["code"] != null){会话["AccessToken"] = GetAccessToken(HttpContext.Request["code"],客户 ID,客户秘密,重定向网址);}if (Session["AccessToken"] != null){accessToken = Session["AccessToken"].ToString();System.Net.WebRequest 请求 = System.Net.WebRequest.Create(String.Format("{0}/Reports",baseUri)) 作为 System.Net.HttpWebRequest;request.Method = "GET";request.ContentLength = 0;request.Headers.Add("授权", String.Format("Bearer {0}", accessToken));使用 (var response = request.GetResponse() as System.Net.HttpWebResponse){使用 (var reader = new System.IO.StreamReader(response.GetResponseStream())){PBIReports 报告 = JsonConvert.DeserializeObject(reader.ReadToEnd());if (Reports.value.Length > 0){PBIReport 报告 = Reports.value[13];返回视图(报告);}}}}获取授权码();返回视图();}
在重定向到this"时,它适用于 power bi 登录页面,在我登录后它会重定向回此页面(因为主页和重定向 url 相同).获取所有报告数据后,一段时间后出现错误消息,指出 http://localhost:34244/Scripts/powerbi.js 中第 5153 行第 11 列的 Unhandled exception0x800a1391 - JavaScript 运行时错误:'Promise' 未定义
然后它说
在 https://app.powerbi.com/13.0.1781.272/scripts/powerbiportal.dependencies.externals.bundle.min.js 的第 1236 行第 335 列引发异常0x80070005 - JavaScript 运行时错误:访问被拒绝.如果有这个异常的处理程序,程序可以安全地继续.在 https://app.powerbi.com/13.0.1781.272/scripts/powerbiportal.common.bundle.min.js 的第 42 行第 17057 列引发异常0x80070005 - JavaScript 运行时错误:访问被拒绝.如果有这个异常的处理程序,程序可以安全地继续.
然后它又开始再次显示第一条错误消息.
这是我的 index.cshtml
<代码>@{ViewBag.Title = "索引";布局 = "~/Views/Shared/_ColumnsOne.cshtml";}<script src="~/Scripts/powerbi.js"></script><脚本类型="文本/javascript">window.onload = 函数(){var accessToken = "@Session["AccessToken"].ToString()";if (!accessToken || accessToken == ""){返回;}var embedUrl = "@Model.embedUrl";var reportId = "@Model.id";变量配置 = {类型:'报告',访问令牌:访问令牌,嵌入网址:嵌入网址,id:reportId,设置:{filterPaneEnabled:假,导航内容窗格启用:假}};常量过滤器 = {$schema: "http://powerbi.com/product/schema#basic",目标: {表:查询1",栏目:学号"},运算符:在",值:[10"]};var reportContainer = document.getElementById('reportContainer');var report = powerbi.embed(reportContainer, config);report.on("加载", function () {var logView = document.getElementById('logView');logView.innerHTML = logView.innerHTML + "已加载<br/>";report.off("加载");});report.on("渲染", function () {var logView = document.getElementById('logView');logView.innerHTML = logView.innerHTML + "渲染<br/>";report.off("渲染");});report.setFilters([过滤器]).then(函数(结果){日志.log(结果);}).catch(函数(错误){日志.log(错误);});};</脚本><div ID="reportContainer" style="width: 900px; height: 550px"></div></div>解决方案IE 还不支持 Promise.您可以通过包含外部库来启用支持.请在此处查看 Microsoft 关于 Power BI 的评论 - 支持 IE8 和 Promises?
我在 IE11 上遇到了同样的问题,这个建议奏效了!希望对你也有帮助.
I have created a power bi report. I want to embed this report to my MVC site. Here is my code:-
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<PBIReports>(reader.ReadToEnd()); if (Reports.value.Length > 0) { PBIReport report = Reports.value[13]; return View(report); } } } } GetAuthorizationCode(); return View(); }
On Redirecting to "this", it goes for power bi login page and after I sign in it redirects back to this page (as homepage and redirect url are same). After getting all the report data, after some time a error message comes up saying
Unhandled exception at line 5153, column 11 in http://localhost:34244/Scripts/powerbi.js 0x800a1391 - JavaScript runtime error: 'Promise' is undefined
After that it says
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.
And then again it starts Showing the first error message again.
Here is my index.cshtml
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_ColumnsOne.cshtml"; } <script src="~/Scripts/powerbi.js"></script> <script type="text/javascript"> 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<br/>"; report.off("loaded"); }); report.on("rendered", function () { var logView = document.getElementById('logView'); logView.innerHTML = logView.innerHTML + "Rendered<br/>"; report.off("rendered"); }); report.setFilters([filter]) .then(function (result) { Log.log(result); }) .catch(function (errors) { Log.log(errors); }); }; </script> <div> <div ID="reportContainer" style="width: 900px; height: 550px"></div> </div>
解决方案IE does not yet support Promise. You can enable support by including an external library. Please see Microsoft's comments on this in relation to Power BI here - Support for IE8 and Promises?
I had the same issue with IE11 and the suggestion worked! Hope it helps you too.
这篇关于嵌入 Power Bi Report Promise 未定义 powerbi.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!