Example T1266420
Visible to All Users

Reporting for Web - Integrate .NET Aspire Dashboard to the ASP.NET Core Reporting App

This example shows a .NET Aspire Dashboard integrated into an ASP.NET Core Document Viewer application.

.net aspire dashboard for asp .net code document viewer

Prerequisites

To work with .NET Aspire, you need the following:

Add DevExpress NuGet Packages

Reference the following NuGet packages in your Reporting application:

  • DevExpress.Aspire.Reporting
  • DevExpress.Aspire.AspNetCore.Reporting

Implementation Details

  1. Add the following project references:
    Project Reference
    AppHost/Orchestration project (usually with an *.AppHost suffix) DevExpress Reports application
    DevExpress Reports application ServiceDefaults application
  2. Open your reporting project. Add the following method calls to Program.cs:
    C#
    var builder = WebApplication.CreateBuilder(args); builder.Services.AddDevExpressControls(); // Important note: Enable .NET Aspire integration after an AddDevExpressControls method call // Enable service discovery and configure OpenTelemetry metrics and tracing for .NET Aspire. // Learn more at: https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/service-defaults builder.AddServiceDefaults(); // Share trace data with the .NET Aspire Dashboard from DevExpress Reports document creation and exporting builder.AddReporting(); // Share trace and metrics data with the .NET Aspire Dashboard for the DevExpress Reports back end services builder.AddAspNetCoreReporting();
  3. Navigate to the AppHost project. Add the following project reference code to Program.cs:
    C#
    var builder = DistributedApplication.CreateBuilder(args); builder.AddProject<Projects.DevExpressReportingApp>("webreporting") .WithExternalHttpEndpoints(); builder.Build().Run();
  4. Build and run the *.AppHost solution to view output in the .NET Aspire dashboard.

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

AspireStarterApp/DevExpressReportingApp/Program.cs
C#
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using DevExpress.AspNetCore; using DevExpress.AspNetCore.Reporting; using DevExpress.Security.Resources; using DevExpress.XtraReports.Web.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using DevExpressReportingApp.Services; using DevExpressReportingApp.Data; var builder = WebApplication.CreateBuilder(args); builder.Services.AddDevExpressControls(); builder.AddServiceDefaults(); builder.AddReporting(); builder.AddAspNetCoreReporting(); builder.Services.AddScoped<ReportStorageWebExtension, CustomReportStorageWebExtension>(); builder.Services.AddMvc(); builder.Services.ConfigureReportingServices(configurator => { if(builder.Environment.IsDevelopment()) { configurator.UseDevelopmentMode(); } configurator.ConfigureReportDesigner(designerConfigurator => { designerConfigurator.RegisterDataSourceWizardConnectionStringsProvider<CustomSqlDataSourceWizardConnectionStringsProvider>(); designerConfigurator.RegisterDataSourceWizardJsonConnectionStorage<CustomDataSourceWizardJsonDataConnectionStorage>(true); }); configurator.ConfigureWebDocumentViewer(viewerConfigurator => { viewerConfigurator.UseCachedReportSourceBuilder(); viewerConfigurator.RegisterJsonDataConnectionProviderFactory<CustomJsonDataConnectionProviderFactory>(); viewerConfigurator.RegisterConnectionProviderFactory<CustomSqlDataConnectionProviderFactory>(); }); }); builder.Services.AddDbContext<ReportDbContext>(options => options.UseSqlite(builder.Configuration.GetConnectionString("ReportsDataConnectionString"))); var app = builder.Build(); using(var scope = app.Services.CreateScope()) { var services = scope.ServiceProvider; services.GetService<ReportDbContext>().InitializeDatabase(); } var contentDirectoryAllowRule = DirectoryAccessRule.Allow(new DirectoryInfo(Path.Combine(builder.Environment.ContentRootPath, "Content")).FullName); AccessSettings.ReportingSpecificResources.TrySetRules(contentDirectoryAllowRule, UrlAccessRule.Allow()); DevExpress.XtraReports.Configuration.Settings.Default.UserDesignerOptions.DataBindingMode = DevExpress.XtraReports.UI.DataBindingMode.Expressions; app.UseDevExpressControls(); System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; if(app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run();
AspireStarterApp/AspireStarterApp.AppHost/Program.cs
C#
var builder = DistributedApplication.CreateBuilder(args); var apiService = builder.AddProject<Projects.AspireStarterApp_ApiService>("apiservice"); builder.AddProject<Projects.AspireStarterApp_Web>("webfrontend") .WithExternalHttpEndpoints() .WithReference(apiService); builder.AddProject<Projects.DevExpressReportingApp>("webreporting") .WithExternalHttpEndpoints(); builder.Build().Run();

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.