Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi we are using Power BI embedded with javascript sdk on an old-school C# .net webforms app. Our markup file looks like this:
<%@ Page Title="System Analytics" Language="C#" MasterPageFile="~/Master/AdminPages.Master" AutoEventWireup="false" CodeBehind="SystemAnalytics.aspx.cs" Inherits="Com.Wolfgang.BCycle.EnterpriseSystem.Web.Admin.Reports.SystemAnalytics" %> <%@ Import Namespace="System.Web.Optimization" %> <asp:Content ID="BodyContent" ContentPlaceHolderID="body" runat="server"> <%: Scripts.Render("~/Scripts/Admin/PowerBIReports") %> <h1 class="page-title">System Analytics</h1> <div id="reportContainer" style="height: 550px; width: 870px; margin: auto;"></div> <script type="text/javascript"> $(function () { var models = window['powerbi-client'].models; var reportId = '<%= ReportId %>'; var groupId = '<%= GroupId %>'; var config = { type: 'report', id: reportId, embedUrl: 'https://app.powerbi.com/reportEmbed?reportId=' + reportId + '&groupId=' + groupId, tokenType: models.TokenType.Embed, accessToken: '<%= EmbedToken %>', permissions: models.Permissions.Read, viewMode: models.ViewMode.View, settings: { filterPaneEnabled: false, navContentPaneEnabled: true } }; var report = powerbi.embed($('#reportContainer').get(0), config); report.on("error", function (event) { console.log(JSON.stringify(event.detail, null, " ")); }); }); </script> </asp:Content>
....and our codebehind looks like this:
using Com.Wolfgang.BCycle.EnterpriseSystem.Core.Diagnostics.Logging; using Com.Wolfgang.BCycle.EnterpriseSystem.Web.Base; using Microsoft.IdentityModel.Clients.ActiveDirectory; using Microsoft.PowerBI.Api.V2; using Microsoft.PowerBI.Api.V2.Models; using Microsoft.Rest; using System; using System.Configuration; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Com.Wolfgang.BCycle.EnterpriseSystem.Web.Admin.Reports { public partial class SystemAnalytics : ModernBCyclePage { protected string Username => ConfigurationManager.AppSettings["PBI.Username"]; protected string Password => ConfigurationManager.AppSettings["PBI.Password"]; protected string ReportId => ConfigurationManager.AppSettings["PBI.AggregateReportId"]; protected string GroupId => ConfigurationManager.AppSettings["PBI.GroupId"]; protected string ClientId => ConfigurationManager.AppSettings["PBI.ClientId"]; protected string AccessToken => GetAuthResultAsync().Result?.AccessToken; protected string EmbedToken => GetEmbedTokenAsync(ReportId).Result?.Token; protected const string ApiUrl = "https://api.powerbi.com/"; protected const string ResourceUrl = "https://analysis.windows.net/powerbi/api"; protected const string AuthorityUrl = "https://login.windows.net/common/oauth2/authorize"; protected async Task<AuthenticationResult> GetAuthResultAsync() => await new AuthenticationContext(AuthorityUrl) .AcquireTokenAsync(ResourceUrl, ClientId, new UserPasswordCredential(Username, Password)); protected async Task<EmbedToken> GetEmbedTokenAsync(string reportId) { try { using (var client = new PowerBIClient(new Uri(ApiUrl), new TokenCredentials(AccessToken, "Bearer"))) { var report = (await client.Reports.GetReportsInGroupAsync(GroupId))? .Value?.FirstOrDefault(r => r.Id == reportId); if (report == null) { return null; } // this is how we filter using "row-level-security" var effectiveUsername = CurrentUserContext.ProgramId; var effectiveIdentity = new EffectiveIdentity( effectiveUsername.ToString(), new[] { report.DatasetId }, roles: new[] { "ProgramId" } ); var embedTokenRequest = new GenerateTokenRequest("View", effectiveIdentity); return await client.Reports.GenerateTokenInGroupAsync(GroupId, reportId, embedTokenRequest); } } catch (Exception ex) { Log.WriteError($"Aggregate Report error authenticating - {ex.Message}", ex); return null; } } } }
This is the error we get client side in the browser console:
{ "message": "OpenConnectionError", "detailedMessage": "Can't display the visual.. Could not render a report visual titled: Rider Trips by Start Day of Week", "technicalDetails": { "requestId": "24f14790-4796-405a-a364-adc4c062756e" } }
At one point everything was working perfectly and embedding perfectly and then at some point the embedding started giving us this message but the report still works on https://app.powerbi.com and in Power BI Desktop. We are not quite sure what was changed but maybe someone on our team saved something unintended without noticing it. Please advise what to double check. Thank you.
Solved! Go to Solution.
Alright I figured out my own problem. It turned out the the report definition was changed. Specifically the security role name had been changed from "ProgramId" to "Security." I changed it back to "ProgramId" and everything works again.
Alright I figured out my own problem. It turned out the the report definition was changed. Specifically the security role name had been changed from "ProgramId" to "Security." I changed it back to "ProgramId" and everything works again.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
13 | |
2 | |
2 | |
1 | |
1 |
User | Count |
---|---|
20 | |
3 | |
2 | |
2 | |
2 |