Back to Devexpress

Document Viewer Server-Side Configuration (ASP.NET Core)

xtrareports-400197-web-reporting-asp-net-core-reporting-server-side-configuration-document-viewer-server-side-configuration-asp-net-core.md

latest6.6 KB
Original Source

Document Viewer Server-Side Configuration (ASP.NET Core)

  • Aug 21, 2025
  • 6 minutes to read

This document describes how to create and configure an ASP.NET Core application as a server-side solution to use the HTML5 Document Viewer in JavaScript. You can use the DevExpress or Visual Studio template to create an application.

Tip

You can also use the dx.aspnetcore.reporting.backend CLI template to create a back-end application. For more information, refer to the following topic: Reporting CLI Project Templates.

Step 1. Create an ASP.NET Core Application

Use DevExpress Template or Microsoft Visual Studio Template to create a new project.

Use DevExpress Template

You can use the Template Gallery to create a new ASP.NET Core project as follows:

  1. Invoke the DevExpress Template Gallery, select Reporting Application under the .NET category and click Create Project.

  2. Set Add Viewer Page to true to add the Document Viewer to the web application.

Note

The template generates a sample storage (a ReportStorageWebExtension descendant) for demonstration purposes only. Create your own implementation for use in production.

Refer to the following help topic for details: Create an ASP.NET Core Application with the Document Viewer.

Use Microsoft Visual Studio Template

You can create an ASP.NET Core application based on the built-in Visual Studio template and configure it for the DevExpress Document Viewer as follows:

  1. Create a new ASP.NET Core Web Application (or open an existing application).

  2. Right-click the Dependencies node in the Solution Explorer and select Manage NuGet Packages in the invoked context menu.

  3. Select DevExpress <:xx.x: Local in the Package source drop-down list and go to the Browse page. Find the DevExpress.AspNetCore.Reporting package and install it.

  4. Open the Program.cs file and and modify it to configure services as demonstrated below:

  5. Implement a controller to process Document Viewer requests. In the Controllers folder, create the ReportingControllers.cs file with the following content:

  6. Add reports to the application.

  7. Add a server-side report storage. To implement a report storage, add a new class inherited from the ReportStorageWebExtension class as described in the ReportStorageWebExtension help topic. Refer to the following help topic for more information and report storage examples: Add a Report Storage (ASP.NET Core).

  8. Register the report storage implemented in the previous step as a scoped service. Open the Program.cs file and add the following code :

Step 2. Configure the Application

Enable cross-origin requests (CORS). Specify the policy that allows any local application to access the report’s back-end. Use the SetIsOriginAllowed method to set it up.

Call the UseCors method and pass the policy name as a parameter. The UseCors method should be called after the UseRouting method and before any MVC-related code. Place the UseCors method before the UseMvc or UseEndpoints methods.

Open the application startup file and insert the following code:

csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCors(options => {
    options.AddPolicy("AllowCorsPolicy", builder => {
        // Allow all ports on local host.
        builder.SetIsOriginAllowed(origin => new Uri(origin).Host == "localhost");
        builder.AllowAnyHeader();
        builder.AllowAnyMethod();
    });
});

var app = builder.Build();

app.UseRouting();
app.UseCors("AllowCorsPolicy");

app.UseEndpoints(endpoints => {
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
});

app.Run();

Step 3. Determine the Host URL

Examine the address string in the browser to determine the host URL and application port.

You can use the Debug section of the Project Properties dialog to view and change the port number:

If you do not use Visual Studio to run the project, inspect the launchSettings.json file. If your application uses HTTPS redirection and calls the UseHttpsRedirection method at startup, the port number is specified in the sslPort setting.

The URL and port number are required for the host setting when you configure the client application as described in the following help topics:

See Also

Add a Document Viewer to an ASP.NET Core Application (MVC)

Redistribution and Deployment (ASP.NET Core Reporting)