DEV Community

IronSoftware
IronSoftware

Posted on

Apply IronPDF License Key in C# (A Simple Guide)

After purchasing IronPDF, I spent 20 minutes troubleshooting "trial expired" errors. The license key was valid, but I'd applied it incorrectly. Production deployment failed.

The solution was simple once I understood the three application methods. Here's how to license IronPDF correctly.

How Do I Apply a License Key?

Set the key in code before using IronPDF:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";

// Now use IronPDF
var renderer = new [ChromePdfRenderer](https://ironpdf.com/blog/videos/how-to-render-webgl-sites-to-pdf-in-csharp-ironpdf/)();
var pdf = renderer.RenderHtmlAsPdf("<h1>Licensed</h1>");
pdf.SaveAs("output.pdf");
Enter fullscreen mode Exit fullscreen mode

Place this at application startup, before any IronPDF calls.

Where Do I Get a License Key?

Purchase from IronPDF licensing page. After purchase, you receive an email with your license key in this format:

IRONPDF-MYCOMPANY-KEY-ABC123-DEF456
Enter fullscreen mode Exit fullscreen mode

Free trial keys are also available for 30-day evaluation.

Can I Store the Key in Configuration?

Yes. In appsettings.json:

{
  "IronPdf.LicenseKey": "IRONPDF-MYLICENSE-KEY-1EF01"
}
Enter fullscreen mode Exit fullscreen mode

IronPDF reads this automatically at startup. No code changes needed.

How Do I Use Web.config or App.config?

Add to <appSettings>:

<configuration>
  <appSettings>
    <add key="IronPdf.LicenseKey" value="IRONPDF-MYLICENSE-KEY-1EF01" />
  </appSettings>
</configuration>
Enter fullscreen mode Exit fullscreen mode

Works for .NET Framework applications.

Which Method Should I Use?

Code (recommended): Most reliable. Works in all environments (Azure, Docker, serverless).

appsettings.json: Clean for .NET Core/6+. Easy to change per environment.

Web.config: Legacy .NET Framework apps only.

I use code-based licensing in production to avoid configuration issues during deployments.

How Do I Verify the License Worked?

Check the IsLicensed property:

IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";

if (IronPdf.License.IsLicensed)
{
    Console.WriteLine("License activated successfully");
}
else
{
    Console.WriteLine("License activation failed");
}
Enter fullscreen mode Exit fullscreen mode

Or validate a specific key:

bool isValid = IronPdf.License.IsValidLicense("IRONPDF-MYLICENSE-KEY-1EF01");
Enter fullscreen mode Exit fullscreen mode

What If Licensing Fails?

Common issues:

Wrong key format: Ensure you copied the entire key including hyphens.

License not set early enough: Apply license before any IronPDF calls, ideally in Program.cs or Startup.cs.

Environment variables: Some environments reset config between requests. Use code-based licensing instead.

Expired trial: Trial keys last 30 days. Purchase a full license to continue.

How Do I License in ASP.NET Core?

In Program.cs (before app.Run()):

using IronPdf;

var builder = WebApplication.CreateBuilder(args);

// Apply license early
IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";

// ... rest of setup

var app = builder.Build();
app.Run();
Enter fullscreen mode Exit fullscreen mode

This ensures licensing happens once at startup, not per request.

Can I Use Environment Variables?

Yes, but read them in code:

string licenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE");
IronPdf.License.LicenseKey = licenseKey;
Enter fullscreen mode Exit fullscreen mode

Set environment variable in Azure App Service, Docker, or CI/CD:

export IRONPDF_LICENSE="IRONPDF-MYLICENSE-KEY-1EF01"
Enter fullscreen mode Exit fullscreen mode

How Do I License in Azure Functions?

Add to function app startup:

[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]

namespace MyNamespace
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Or use Application Settings in Azure Portal (reads as environment variable).

What About Docker Containers?

Pass license as environment variable in Dockerfile:

ENV IRONPDF_LICENSE="IRONPDF-MYLICENSE-KEY-1EF01"
Enter fullscreen mode Exit fullscreen mode

Or at runtime:

docker run -e IRONPDF_LICENSE="IRONPDF-MYLICENSE-KEY-1EF01" myapp
Enter fullscreen mode Exit fullscreen mode

Then read in code:

IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE");
Enter fullscreen mode Exit fullscreen mode

Do I Need a License for Development?

No. Use the free trial for development and testing. Apply a purchased license only for production deployments.

Trial limitations:

  • 30-day time limit
  • Watermark on generated PDFs
  • Full feature access

Purchase a license when deploying to production.

How Do I Handle Multiple Environments?

Use different config files per environment:

appsettings.Development.json:

{
  "IronPdf.LicenseKey": "IRONPDF-TRIAL-KEY"
}
Enter fullscreen mode Exit fullscreen mode

appsettings.Production.json:

{
  "IronPdf.LicenseKey": "IRONPDF-PRODUCTION-KEY"
}
Enter fullscreen mode Exit fullscreen mode

ASP.NET Core loads the correct file based on ASPNETCORE_ENVIRONMENT.

Can I Share a License Across Applications?

Depends on your license type. Standard licenses cover one deployment. Enterprise licenses cover multiple deployments.

Check your license agreement or contact Iron Software support for clarification.

What If My Key Stops Working?

Licenses don't expire, but they're version-specific. If you upgrade IronPDF major versions, you may need to renew your license.

Example: License purchased for IronPDF 2023.x doesn't work with IronPDF 2025.x.

How Do I Test Licensing in CI/CD?

Store license in CI/CD secrets (GitHub Actions, Azure DevOps, GitLab CI):

# GitHub Actions
- name: Set License
  run: echo "IRONPDF_LICENSE=${{ secrets.IRONPDF_LICENSE }}" >> $GITHUB_ENV

- name: Run Tests
  run: dotnet test
Enter fullscreen mode Exit fullscreen mode

Read in tests:

[TestInitialize]
public void Setup()
{
    IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE");
}
Enter fullscreen mode Exit fullscreen mode

Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.

Top comments (0)