How to pass configuration settings to ReportProcessor in ASP.NET Core application that does not use REST Service

Environment

Product Version 13.0.19.116 and higher
Product Progress® Telerik® Reporting
Project Type ASP.NET Core

Description

If you want to export a report in ASP.NET Core application with the ReportProcessor without using the Telerik Reporting REST Service, you may need the configuration settings from the appsettings.json file. For example, when the report uses external user functions, their assembly should be registered in the telerikReporting section of the configuration file - Extending Expressions.

Solution

  1. You need to create a code which ensures reading the appsettings.json as a configuration file. For example with the following class :
public class ConfigurationService
{
    public IConfiguration Configuration { get; private set; }

    public IHostingEnvironment Environment { get; private set; }
    public ConfigurationService(IHostingEnvironment environment)
    {
        this.Environment = environment;

        var configFileName = System.IO.Path.Combine(environment.ContentRootPath, "appsettings.json");
        var config = new ConfigurationBuilder()
                        .AddJsonFile(configFileName, true)
                        .Build();

        this.Configuration = config;
    }
}
  1. Then you need to put the above service in the container in the Startup.cs -> ConfigureServices class, like :
public void ConfigureServices(IServiceCollection services)
{
    this.services = services;
    this.services.Configure<CookiePolicyOptions>(options =>
    {
        options.CheckConsentNeeded = context => true;
        options.MinimumSameSitePolicy = SameSiteMode.None;
    });

    this.services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    this.services.AddSingleton<ConfigurationService>();
}

For details on the above settings you may check How to implement Telerik Reporting in ASP.NET Core 2.1 MVC.

  1. The next step is to use the ReportProcessor with its overload specific for .NET Standard that takes as an argument the configuration - in an MVC controller you may inject it in the constructor of the controller:
private readonly ConfigurationService configuration;

public HomeController(ConfigurationService configuration)
{
    this.configuration = configuration;
}

or alternatively, take it from the HttpContext:

var configuration = this.HttpContext.RequestServices.GetService(typeof(ConfigurationService)) as ConfigurationService;

and use it like:

ReportProcessor reportProcessor = new ReportProcessor(configuration.Configuration);
In this article
Not finding the help you need? Improve this article