Click or drag to resize

ASP.NET Setup for .NET Core & .NET 5+

ASP.NET Core / ASP.NET 5 setup for RAD PDF requires a reference to the RadPdf NuGet in your web application and minor changes to your site's Program.cs and Startup.cs files.

Web Control Installation

In Visual Studio, right click your ASP.NET project and select Manage NuGet Packages.... Search the nuget.org package source for:

RadPdf

Web Site Startup.cs Requirements

In order to use the RAD PDF Web Control, additions will need to be made to your web application's Startup.cs file.

RAD PDF Middleware

RAD PDF's middleware must be configured in the Configure(IApplicationBuilder app, IHostingEnvironment env) method of the Startup class of your web application. This is done by simply making sure that it includes both:

  • A reference to the RadPdf namespace
  • A call to the IApplicationBuilder extension method UseRadPdf()

For example:

C#
...
using RadPdf;
...

public class Startup
{
    ...

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        ...
        app.UseRadPdf();
        ...
    }
}

RAD PDF Middleware Settings

The following properties of a RadPdfCoreMiddlewareSettings instance can be used to configure the RAD PDF middleware.

NameTypeDescription
ConnectionString String If using the PdfWebControl, the SQL Server connection string RAD PDF should use.
IntegrationProvider PdfIntegrationProvider An instance of a custom PdfIntegrationProvider. This allows your application to hook into RAD PDF callbacks, define custom session / storage providers, and more.
LicenseKey String A RAD PDF License Key provided by Red Software (or "DEMO" for evaluations).
Web Site Sample Setup.cs

The following is a sample Startup.cs file used to configure RAD PDF with a .NET 5 web site:

C#
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

//Add a reference to the RadPdf namespace
using RadPdf;

namespace RadPdfNet5Demo
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();

            //Default RAD PDF session provider relies on ASP.NET session state.
            //A custom session provider can be used to avoid use of this.
            services.AddSession();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();

            app.UseRouting();

            // Default RAD PDF session provider relies on ASP.NET session state, so call this before .UseRadPdf()
            // A custom session provider can be used to avoid use of this.
            app.UseSession();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
            });

            // Create middleware settings
            RadPdfCoreMiddlewareSettings settings = new RadPdfCoreMiddlewareSettings() { ConnectionString = "Server=.;Database=RadPdf;Trusted_Connection=Yes;", LicenseKey = "DEMO" };

            // Add RAD PDF's middleware to app
            app.UseRadPdf(settings);
        }
    }
}

See Also