ASP.NET Core middleware is a software to handle HTTP requests and response. Each middleware component serves a specific purpose like one middleware authenticates a user, the other middleware handles the static files like javascript or css files. These middleware components together setup a request processing pipeline.
The request pipeline is configured in the Configure method in the Startup class. It is these middleware components in the pipeline that determine how a request is processed in ASP.NET Core. The default code developed by the ASP.NET Core Web App template sets up the request processing pipeline for the application using a set of middlewares - UseDeveloperExceptionPage() and UseStaticFiles() of IApplicationBuilder interface. The middlewares are executed in the order in which they are added to the pipeline.
startup.cs |
Copy Code
|
---|---|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); ... } |
To provide access to a report output from the browser, you need to configure ActiveReports JSViewer in ASP.NET Core middleware. It is done by adding the UseReporting() middleware in Configure method, which configures middleware for ActiveReports API and handlers.
Create an ASP.NET Core Project
Open Microsoft Visual Studio 2019 and select Create a new project.
Select ASP.NET Core Web Application.
Type a name for your project and click Create.
Fill-in the additional info like Target Framework as .NET 5.0 (Current).
Uncheck the 'Configure for HTTPS' checkbox instruction and click Create.
Configure ActiveReports in ASP.NET Core Middleware
Right-click the project in the Solution Explorer and select Manage Nuget Packages.
Add the following package to the project.
GrapeCity.ActiveReports.Aspnetcore.Viewer
Add a new folder called 'Reports' in application's root and place the report you want to display in the viewer, in this folder.
Make sure to set the Build Action property of the report to 'Embedded Resource'.
Open 'Startup.cs' file and add the following 'using' statement at the top.
using GrapeCity.ActiveReports.Aspnetcore.Viewer;
In the Startup.cs file, add the following code snippet inside the Configure method (before app.UseStaticFiles(); statement) to enable the application to use ActiveReports:
Startup.cs |
Copy Code
|
---|---|
app.UseReporting(settings => { settings.UseEmbeddedTemplates("JsViewer_Core.Reports", this.GetType().Assembly); settings.UseCompression = true; }); |