I have a Power BI Report that i want to Embed in ASP.net C# webform without using MVC.
Please can you help me i am a beginner in power bi
I have a Power BI Report that i want to Embed in ASP.net C# webform without using MVC.
Please can you help me i am a beginner in power bi
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Feb 7, 2024, 8:12 AM EST
Check the below link.
https://www.sqlshack.com/how-to-embed-a-power-bi-report-server-report-into-an-asp-net-web-application/
Manikandan MurugesanRank #300 · 8.4K reputationPosted Feb 7, 2024, 11:34 AM EST
Refer the below links: https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-organization-app
https://www.sqlshack.com/how-to-embed-a-power-bi-report-server-report-into-an-asp-net-web-application/
Abhishek YadavRank #217 · 11.3K reputationPosted Feb 8, 2024, 7:20 AM EST
To embed a Power BI report in ASP.NET using C#, you can follow these steps:
Install the Power BI NuGet package:
In the Visual Studio Solution Explorer, right-click on your project and select "Manage NuGet Packages".
Search for "Microsoft.PowerBI.Api" and install the NuGet package.
Create a new ASP.NET web form or web page:
In the Solution Explorer, right-click on your project, select "Add" -> "New Item".
Choose either "Web Form" or "Web Page" and give it a name.
Add a reference to the Power BI API in your web form or web page:
using Microsoft.PowerBI.Api; using Microsoft.PowerBI.Api.Models;Add the necessary HTML elements and JavaScript code to embed the Power BI report:
You can add an iframe tag in your ASP.NET page and set the source URL to the Power BI report's embed URL.
Securely embed the report by generating an embed token:
Get the access token using Azure Active Directory (Azure AD) authentication or any other authentication method of your choice.
Create an instance of a Power BI client, set the access token, and generate an embed token.
using Microsoft.IdentityModel.Clients.ActiveDirectory; using Microsoft.Rest; using Microsoft.Rest.Azure.Authentication; using System.Configuration; string clientId = ConfigurationManager.AppSettings["clientId"]; string clientSecret = ConfigurationManager.AppSettings["clientSecret"]; string tenantId = ConfigurationManager.AppSettings["tenantId"]; var credentials = new ClientCredential(clientId, clientSecret); var client = new PowerBIClient(new TokenCredentials(await GetAccessToken(tenantId, credentials))); var embedTokenRequest = new GenerateTokenRequestV2( reports: new List() { new GenerateTokenRequestV2Report(reportId: "YOUR_REPORT_ID") }); var embedTokenResponse = await client.Reports.GenerateTokenInGroupAsync("YOUR_GROUP_ID", embedTokenRequest);Pass the embed token to the JavaScript code that loads the embedded report:
In your ASP.NET page, add the JavaScript code that sets the access token and embeds the report using the Power BI JavaScript library.
var reportContainer = document.getElementById('reportContainer'); var accessToken = "YOUR_ACCESS_TOKEN"; var embedUrl = "https://app.powerbi.com/reportEmbed?reportId=YOUR_REPORT_ID&w=1"; var config = { type: 'report', tokenType: models.TokenType.Embed, accessToken: accessToken, embedUrl: embedUrl, id: "YOUR_REPORT_ID", permissions: models.Permissions.All, settings: { filterPaneEnabled: true, navContentPaneEnabled: true, } }; var report = powerbi.embed(reportContainer, config);Note: Replace the placeholders 'YOUR_REPORT_ID' and 'YOUR_GROUP_ID' with the actual values for your Power BI report and group.
This will embed the Power BI report in your ASP.NET page without using MVC.