How to Integrate Power BI with ASP.NET

Cody Schneider7 min read

Embedding Power BI reports directly into your ASP.NET application provides a seamless, powerful analytics experience for your users. Instead of sending them to another site, you can bring interactive, real-time data right into the heart of your own platform. This guide breaks down exactly how to accomplish this, from understanding your options to writing the code that makes it all work.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Why Integrate Power BI with ASP.NET?

Before we get into the technical steps, let's quickly cover why this is worth the effort. By bringing Power BI into your ASP.NET application, you centralize the user experience, allowing them to make data-informed decisions without ever leaving your ecosystem.

  • Contextual Insights: You can place reports directly alongside related features. Imagine a sales rep viewing an account page in your CRM and seeing an embedded Power BI report showing that account's purchase history and trends.
  • Seamless User Experience: Users stay signed into your application. There's no need to manage separate logins or switch browser tabs to find analytics. It feels like a native part of your software.
  • Controlled Data Access: By leveraging embedding, you can use features like Row-Level Security (RLS) to ensure users only see the data they are authorized to see, all managed within a single, secure framework.
  • Increased Application Value: A rich, interactive reporting experience is a major value-add that can differentiate your application from competitors.

Understanding Your Embedding Options

Microsoft Power BI offers two primary models for embedding analytics, and choosing the right one is your first critical decision. It all depends on who your audience is.

1. Embed for Your Organization (User Owns Data)

This model is designed for internal applications. Think of a dashboard for your employees, a sales performance tracker for your internal sales team, or a project management overview for your managers.

  • Who is it for? Internal users within your company who already have their own Power BI licenses (Pro or Premium Per User).
  • How Authentication Works: Each user signs in with their own Azure Active Directory (Azure AD) credentials. Your application helps facilitate this login, and the user's Power BI permissions are respected automatically.
  • Cost Model: Your organization pays for each user to have a Power BI license. There are no additional costs for embedding itself.
  • Best Use Case: Building a line-of-business application that enhances workflows for your internal teams.

2. Embed for Your Customers (App Owns Data)

This model is built for external-facing applications, like a software-as-a-service (SaaS) product or a customer portal. Your end-users don't need - and likely won't have - their own Power BI licenses.

  • Who is it for? External customers, clients, or partners who use your application.
  • How Authentication Works: Your application authenticates to the Power BI service using a master identity, which can be a special "master user" account or, more preferably, a Service Principal. This identity is used to generate an embed token for each user session, which grants them permission to view a specific report.
  • Cost Model: This requires purchasing Power BI Embedded capacity (an "A," "EM," or "P" SKU in Azure). You pay for this capacity based on usage, not per user license, which is much more scalable for applications with many external users.
  • Best Use Case: A SaaS platform showing individual customers their own product usage data, a financial portal offering analytics tools to clients, or any multi-tenant application where you provide reporting as a service.

For this tutorial, we will focus on the more common internal use case: Embed for Your Organization. The core principles are similar for both, but this is the most direct path to getting started.

Step-by-Step: Integrating Your First Report

Let's walk through the process of embedding a Power BI report into a modern ASP.NET Core web application from start to finish.

Prerequisites: What You’ll Need

  • An Azure Account: You'll need an Azure subscription with permissions to register applications in Azure AD.
  • A Power BI Pro Account: This is where you will create and host the reports to be embedded.
  • An ASP.NET Core Project: Use Visual Studio or the .NET CLI to create a basic web application project.
  • A Sample Report: Have a Power BI report published to a workspace in your Power BI service that you want to embed. For this example, let's assume it's in "My Workspace."
GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Step 1: Register Your Application in Azure AD

Your ASP.NET app needs an identity in Azure AD to securely call the Power BI APIs. This registration process provides that identity.

  1. Navigate to the Azure Portal.
  2. Go to Azure Active Directory > App registrations.
  3. Click + New registration.
  4. Give your application a name (e.g., "MyWebAppPowerBI").
  5. For "Supported account types," choose "Accounts in this organizational directory only."
  6. Under "Redirect URI (optional)," select "Web" and enter your app's local development URL, which is often https://localhost:5001/signin-oidc. (Adjust port as per your setup.)
  7. Click Register.

Once registered, note the Application (client) ID and Directory (tenant) ID. You'll need these later.

Next, create a client secret:

  1. In your app registration, go to Certificates & secrets.
  2. Click + New client secret.
  3. Add a descriptive name and select an expiration.
  4. Click Add. Copy the Value immediately and store it securely.

Step 2: Assign API Permissions

  1. In your app registration, go to API permissions.
  2. Click + Add a permission.
  3. Select Power BI Service.
  4. Choose Delegated permissions.
  5. Check Report.Read.All.
  6. Click Add permissions.

Step 3: Configure Your ASP.NET Project

In your appsettings.json, include the following, replacing placeholders accordingly:

{
  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "yourdomain.com",
    "TenantId": "YOUR_TENANT_ID",
    "ClientId": "YOUR_CLIENT_ID",
    "ClientSecret": "YOUR_CLIENT_SECRET",
    "CallbackPath": "/signin-oidc"
  },
  "PowerBi": {
    "WorkspaceId": "YOUR_WORKSPACE_ID",
    "ReportId": "YOUR_REPORT_ID"
  },
  "Logging": { ... },
  "AllowedHosts": "*"
}

Find the Workspace and Report IDs in the Power BI service URL when viewing your report.

Next, install NuGet packages:

dotnet add package Microsoft.Identity.Web
dotnet add package Microsoft.Identity.Web.UI
dotnet add package Microsoft.PowerBI.Api

In Program.cs (for .NET 6+):

using Microsoft.AspNetCore.Authentication.OpenIdConnect,
using Microsoft.Identity.Web,
using Microsoft.Identity.Web.UI,

var builder = WebApplication.CreateBuilder(args),

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
        .EnableTokenAcquisitionToCallDownstreamApi(new[] { "https://analysis.windows.net/powerbi/api/.default" })
        .AddInMemoryTokenCaches(),

builder.Services.AddControllersWithViews()
    .AddMicrosoftIdentityUI(),

// other service configurations

var app = builder.Build(),

app.UseAuthentication(),
app.UseAuthorization(),
app.MapControllers(),
app.Run(),

This code configures Azure AD authentication and token acquisition for Power BI API calls.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Step 4: Get Power BI Report Details in Your Controller

Create a controller action to fetch report embedding info:

using Microsoft.AspNetCore.Mvc,
using Microsoft.PowerBI.Api,
using Microsoft.PowerBI.Api.Models,
using Microsoft.Rest,
using Microsoft.AspNetCore.Authorization,
using Microsoft.Identity.Web,
using System,
using System.Threading.Tasks,

public class HomeController : Controller
{
    private readonly ITokenAcquisition _tokenAcquisition,
    private readonly IConfiguration _configuration,

    public HomeController(ITokenAcquisition tokenAcquisition, IConfiguration configuration)
    {
        _tokenAcquisition = tokenAcquisition,
        _configuration = configuration,
    }

    [Authorize]
    public async Task<IActionResult> EmbedReport()
    {
        try
        {
            var accessToken = await _tokenAcquisition.GetAccessTokenForUserAsync(new[] { "https://analysis.windows.net/powerbi/api/.default" }),
            var tokenCredentials = new TokenCredentials(accessToken, "Bearer"),
            using var client = new PowerBIClient(new Uri("https://api.powerbi.com/"), tokenCredentials),
            var workspaceId = Guid.Parse(_configuration["PowerBi:WorkspaceId"]),
            var reportId = Guid.Parse(_configuration["PowerBi:ReportId"]),

            var report = await client.Reports.GetReportInGroupAsync(workspaceId, reportId),
            var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view"),
            var embedToken = await client.Reports.GenerateTokenInGroupAsync(workspaceId, reportId, generateTokenRequestParameters),

            var viewModel = new
            {
                ReportId = report.Id.ToString(),
                EmbedUrl = report.EmbedUrl,
                Token = embedToken.Token
            },

            return View(viewModel),
        }
        catch (Exception)
        {
            return View("Error"),
        }
    }
}

This action authenticates, retrieves report info, and generates an embed token.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Step 5: Render the Report in Your View

Create Views/Home/EmbedReport.cshtml:

@model dynamic

<h2>Here is your embedded Power BI Report</h2>

<div id="reportContainer" style="height: 600px, width: 100%,"></div>

<!-- Power BI JS Library -->
<script src="https://cdn.jsdelivr.net/npm/powerbi-client/dist/powerbi.min.js"></script>
<script>
    var embedUrl = "@Model.EmbedUrl",
    var token = "@Model.Token",
    var reportId = "@Model.ReportId",

    var reportContainer = document.getElementById('reportContainer'),
    var models = window['powerbi-client'].models,

    var config = {
        type: 'report',
        id: reportId,
        embedUrl: embedUrl,
        accessToken: token,
        tokenType: models.TokenType.Embed,
        settings: {
            panes: {
                filters: { expanded: false, visible: true },
                pageNavigation: { visible: true }
            }
        }
    },

    var report = powerbi.embed(reportContainer, config),
</script>

This script uses Power BI JavaScript SDK to embed the report.

Final Thoughts

Integrating Power BI with ASP.NET creates a truly professional and seamless data experience, but as you can see, it requires several configuration steps across Azure, Power BI, and your application code. The power it provides, especially for embedding contextual analytics directly where users work, is well worth the invested development time.

For marketing and sales teams whose primary goal is to quickly understand performance without building a custom application, this developmental overhead can be a major hurdle. When all you need is a dashboard that combines data from tools like Google Analytics, Salesforce, and Shopify, we built a much faster path. With Graphed, you connect your platforms with a few clicks and then simply ask for the reports you need in plain English. We build the interactive, real-time dashboards for you in seconds, saving you from navigating APIs and client-side scripts to get your answers.

Related Articles