Skip to content

ASP NET Core MVC

Peter Gill edited this page Jun 8, 2026 · 3 revisions

ASP.NET Core MVC Integration

Majorsilence.Reporting.RdlAsp.Mvc adds a pre-built report endpoint to an ASP.NET Core application. It scans a folder for .rdl files and exposes routes for listing and rendering them.

Status: the MVC integration is still a work in progress. For production use, the Streaming PDF — ASP.NET Core pattern gives you full control.

Install

dotnet add package Majorsilence.Reporting.RdlAsp.Mvc

Program.cs setup

using Majorsilence.Reporting.Rdl;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Initialise the reporting engine once at startup
RdlEngineConfig.RdlEngineConfigInit();

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

// Register the built-in report routes
app.MapControllerRoute(
    name: "msr",
    pattern: "msr/{controller=RdlReport}/{action=Index}/{id?}");

app.Run();

appsettings.json

Specify the folder that contains your .rdl files:

{
  "Settings": {
    "ReportsFolder": "Reports/"
  }
}

The path is relative to the application's working directory (ContentRootPath). Use an absolute path in production to avoid ambiguity:

{
  "Settings": {
    "ReportsFolder": "/var/reports/"
  }
}

Built-in routes

Route Method Description
/msr/RdlList GET Returns a list of all .rdl files in the reports folder
/msr/RdlReport/ShowFile/{reportFile}/{type?} GET Renders the named report

Report list

GET /msr/RdlList returns a JSON array of available report filenames found in the configured reports folder.

Render a report

GET /msr/RdlReport/ShowFile/MyReport.rdl/pdf

The type segment controls output format. Supported values mirror OutputPresentationType:

type value Output
pdf PDF document
excel Excel 2007 workbook
csv Comma-separated values
html HTML fragment

The response sets the correct Content-Type header and streams the output directly.

Passing parameters via query string

Append report parameters as query string values:

/msr/RdlReport/ShowFile/SalesReport.rdl/pdf?StartDate=2024-01-01&EndDate=2024-12-31

Parameter names must match those defined in the report exactly.

Custom controller approach

For more control — authentication, custom error pages, dynamic connection strings — write your own controller and use the core engine directly:

using Majorsilence.Reporting.Rdl;

[ApiController]
[Route("reports")]
public class ReportsController : ControllerBase
{
    private readonly string _reportsFolder;

    public ReportsController(IConfiguration config)
    {
        _reportsFolder = config["Settings:ReportsFolder"]!;
    }

    [HttpGet("{name}.pdf")]
    public async Task<IActionResult> GetPdf(string name,
        [FromQuery] string? startDate,
        [FromQuery] string? endDate)
    {
        var rdlPath = Path.Combine(_reportsFolder, name + ".rdl");
        if (!System.IO.File.Exists(rdlPath))
            return NotFound();

        var rdlp = new RDLParser(await System.IO.File.ReadAllTextAsync(rdlPath))
        {
            Folder = _reportsFolder
        };
        using var report = await rdlp.Parse();

        if (report.ErrorMaxSeverity > 4)
            return StatusCode(500, report.ErrorItems);

        var parameters = new Dictionary<string, string>();
        if (startDate is not null) parameters["StartDate"] = startDate;
        if (endDate is not null)   parameters["EndDate"]   = endDate;

        await report.RunGetData(parameters.Count > 0 ? parameters : null);

        using var ms = new MemoryStreamGen();
        await report.RunRender(ms, OutputPresentationType.PDF);
        var pdf = ((MemoryStream)ms.GetStream()).ToArray();
        return File(pdf, "application/pdf", name + ".pdf");
    }
}

See Streaming PDF — ASP.NET Core for the full streaming pattern including Excel, CSV, and HTML responses.

Example project

A working example is available in the repository: Majorsilence.Reporting.WebExample

Clone this wiki locally