Create an ASP.NET Core Web API Service
To create an ASP.NET Core Web API service for the Bold Reports® Angular Report Designer, create an ASP.NET Core Web API project, install the BoldReports.Net.Core package, register CORS, and add a reporting API controller.
To get started quickly with an ASP.NET Core Web API for the Report Designer, watch the following video:
Bold Reports® ASP.NET Core supports from
.NET Core 8.0only. So, choose the .NET Core versionASP.NET Core 8.0or higher versions for Designer API creation.
- Start Visual Studio 2022 and click Create new project.
- Choose ASP.NET Core Web API, and then click Next.

- Change the project name, and then click Next.
- In the dropdown for the ASP.NET Core version, choose ASP.NET Core 8.0, then click Create.

If you need to use Bold Reports® with ASP.NET Core on Linux or macOS, then see Can Bold Reports® be used with ASP.NET Core on Linux and macOS.
Which NuGet packages does the Report Designer Web API service need?
The Bold Reports® Report Designer Web API service requires the BoldReports.Net.Core NuGet package. In the Solution Explorer, right-click Dependencies, select Manage NuGet Packages, search for the package BoldReports.Net.Core, and install it in the application. The following table provides details of the package and its usage.
| Package | Purpose |
|---|---|
BoldReports.Net.Core |
Builds the server-side implementations. |
When you install the preceding NuGet package, it automatically adds the following Report Designer dependent NuGet packages to your application.
| Package | Purpose |
|---|---|
Syncfusion.Compression.Net.Core |
Supports for exporting the report to PDF, Microsoft Word, and Microsoft Excel format. It is a base library for the packages Syncfusion.Pdf.Net.Core , Syncfusion.DocIO.Net.Core and Syncfusion.XlsIO.Net.Core. |
Syncfusion.Pdf.Net.Core |
Supports for exporting the report to a PDF. |
Syncfusion.DocIO.Net.Core |
Supports for exporting the report to a Word. |
Syncfusion.XlsIO.Net.Core |
Supports for exporting the report to an Excel. |
Syncfusion.OfficeChart.Net.Core |
It is a base library of the Syncfusion.XlsIO.Net.Core package. |
Newtonsoft.Json |
Serialize and deserialize the data or report for report designer. It is a mandatory package for the report designer, and the package version should be 13.0.3 or higher for .NET 8.0 Core or higher. |
Microsoft.Data.SqlClient |
This is an optional package for the report viewer and designer. It should be referred in project when process the RDL report and which contains the SQL Server and SQL Azure data source. Also, the package version should be 5.1.0 or higher. |
For details about installing and configuring the Report Designer NuGet packages, see NuGet packages for the Angular Report Designer.
Register CORS
To register CORS for the Bold Reports® Report Designer Web API service, add AddCors and AddMemoryCache in Program.cs. Browser security prevents the Report Designer from making requests to your API service when they run in different domains. To allow access to your API service from a different domain, you must enable cross-origin requests.
Register AddCors and AddMemoryCache in Program.cs to add CORS services to the application’s service container. Replace the following code to allow any origin requests.
builder.Services.AddCors(o => o.AddPolicy("AllowAllOrigins", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));
builder.Services.AddMemoryCache();
.......
.......
app.UseHttpsRedirection();
app.UseCors();
app.UseAuthorization();For more information about CORS, see Configure CORS for API. For details about memory caching, see Configure Memory Cache
Add API Service
To add the API service for the Bold Reports® Report Designer, add an API Controller class named ReportingAPIController to the project.
- Right-click the project and select Add > New Item from the context menu.
- In the Add New Item dialog, select API Controller class and name it as
ReportingAPIController, and then click Add.
While adding API Controller class, name it with the suffix
Controllerthat is mandatory.
Configure Web API
To configure the Web API controller for the Bold Reports® Report Designer, implement the IReportDesignerController interface in ReportingAPIController and use the ReportDesignerHelper and ReportHelper classes. The IReportDesignerController interface contains the required actions and helper methods declaration to process the designer file and data actions. The ReportDesignerHelper and ReportHelper classes contain methods that help process Post or Get requests from the control and return the response.
| Methods | Description |
|---|---|
| PostDesignerAction | Action (HttpPost) method for posting the request for designer actions. |
| UploadReportAction | Action (HttpPost) method for posted file actions. |
| SetData | Writes the resource into storage location. |
| GetData | Reads the resource from storage location. |
| GetImage | Action (HttpGet) method for getting resource of images in the report. |
| PostReportAction | Action (HttpPost) method for posting the request for report process. |
| GetResource | Action (HttpGet) method for getting resource for report. |
| OnInitReportOptions | Report initialization method that occurs when the report is about to be processed. |
| OnReportLoaded | Report loaded method that occurs when the report and sub report start loading. |
ReportDesignerHelper
The class ReportDesignerHelper contains helper methods that help process Post or Get requests from the Report Designer control and return the response to the Report Designer control. It has the following methods.
| Methods | Description |
|---|---|
| GetResource | Returns the report resource for the requested key. |
| ProcessReport | Processes the report request and returns the result. |
ReportHelper
The class ReportHelper contains helper methods that help process Post or Get requests for the report preview action and return the response to the Report Designer. It has the following methods.
| Methods | Description |
|---|---|
| GetResource | Returns the report resource for the requested key. |
| ProcessReport | Processes the report request and returns the result. |
-
Open the
ReportingAPIControllerand add the following using statement.using BoldReports.Web.ReportViewer; using BoldReports.Web.ReportDesigner; -
Add the
{action}placeholder in the route template, if the default controller attribute does not contain it.[Route("api/[controller]/[action]")] public class ReportingAPIController : Controller { } -
Next, add the
[EnableCors]attribute to theReportingAPIControllerclass and specify the policy name given inStartup.ConfigureServices.[Microsoft.AspNetCore.Cors.EnableCors("AllowAllOrigins")] [Route("api/[controller]/[action]")] public class ReportingAPIController : Controller, BoldReports.Web.ReportDesigner.IReportDesignerController { } -
Inherit the
IReportDesignerControllerinterface, and implement its methods (replace the following code in newly created Web API controller).[Microsoft.AspNetCore.Cors.EnableCors("AllowAllOrigins")] [Route("api/[controller]/[action]")] public class ReportingAPIController : Controller, BoldReports.Web.ReportDesigner.IReportDesignerController { private Microsoft.Extensions.Caching.Memory.IMemoryCache _cache; private Microsoft.AspNetCore.Hosting.IWebHostEnvironment _hostingEnvironment; public ReportingAPIController(Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache, Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment) { _cache = memoryCache; _hostingEnvironment = hostingEnvironment; } [NonAction] private string GetFilePath(string itemName, string key) { string rootPath = this._hostingEnvironment.WebRootPath ? this._hostingEnvironment.WebRootPath : this._hostingEnvironment.ContentRootPath; string dirPath = Path.Combine(rootPath, "Cache", key); if (!System.IO.Directory.Exists(dirPath)) { System.IO.Directory.CreateDirectory(dirPath); } return Path.Combine(dirPath, itemName); } public object GetImage(string key, string image) { return ReportDesignerHelper.GetImage(key, image, this); } public object GetResource(ReportResource resource) { return ReportHelper.GetResource(resource, this, _cache); } [NonAction] public void OnInitReportOptions(ReportViewerOptions reportOption) { } [NonAction] public void OnReportLoaded(ReportViewerOptions reportOption) { } [HttpPost] public object PostDesignerAction([FromBody] Dictionary<string, object> jsonResult) { return ReportDesignerHelper.ProcessDesigner(jsonResult, this, null, this._cache); } public object PostFormDesignerAction() { return ReportDesignerHelper.ProcessDesigner(null, this, null, this._cache); } public object PostFormReportAction() { return ReportHelper.ProcessReport(null, this, this._cache); } [HttpPost] public object PostReportAction([FromBody] Dictionary<string, object> jsonResult) { return ReportHelper.ProcessReport(jsonResult, this, this._cache); } [NonAction] public bool SetData(string key, string itemId, ItemInfo itemData, out string errorMessage) { errorMessage = string.Empty; if (itemData.Data != null) { System.IO.File.WriteAllBytes(this.GetFilePath(itemId, key), itemData.Data); } else if (itemData.PostedFile != null) { var fileName = itemId; if (string.IsNullOrEmpty(itemId)) { fileName = System.IO.Path.GetFileName(itemData.PostedFile.FileName); } using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { itemData.PostedFile.OpenReadStream().CopyTo(stream); byte[] bytes = stream.ToArray(); var writePath = this.GetFilePath(fileName, key); System.IO.File.WriteAllBytes(writePath, bytes); stream.Close(); stream.Dispose(); } } return true; } [NonAction] public ResourceInfo GetData(string key, string itemId) { var resource = new ResourceInfo(); try { var filePath = this.GetFilePath(itemId, key); if (itemId.Equals(Path.GetFileName(filePath), StringComparison.InvariantCultureIgnoreCase) && System.IO.File.Exists(filePath)) { resource.Data = System.IO.File.ReadAllBytes(filePath); } else { resource.ErrorMessage = "File not found from the specified path"; } } catch (Exception ex) { resource.ErrorMessage = ex.Message; } return resource; } [HttpPost] public void UploadReportAction() { ReportDesignerHelper.ProcessDesigner(null, this, this.Request.Form.Files[0], this._cache); } } -
Compile and run the Web API service application.