Configuración de la clave de licencia en Web.config

This article was translated from English: Does it need improvement?
Translated
View the article in English

Este problema ha sido resuelto desde la versión 2024.3.3 de IronPDF.

Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronPDF must be licensed for development.
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronPDF must be licensed for development.
SHELL

Para las versiones más antiguas de IronPdf, específicamente aquellas entre las versiones 2023.4.4 y 2024.3.3, existe un problema de licenciamiento conocido en:

  • Proyectos de ASP.NET
  • Versión de .NET Framework >= 4.6.2

    La clave almacenada en un archivo Web.config NO será reconocida ni utilizada por el producto.

Solución

Para abordar este problema, se recomienda recuperar la clave de licencia del archivo Web.config utilizando ConfigurationManager en el código, y luego aplicarla a la propiedad License.LicenseKey.

Ejemplo:

<configuration>
...
  <appSettings>
    <add key="IronPdf.LicenseKey" value="IRONPDF-MYLICENSE-KEY-1EF01"/>
  </appSettings>
...
</configuration>
<configuration>
...
  <appSettings>
    <add key="IronPdf.LicenseKey" value="IRONPDF-MYLICENSE-KEY-1EF01"/>
  </appSettings>
...
</configuration>
XML

Con el archivo XML proporcionado arriba, podemos usar ConfigurationManager para recuperar el valor de la clave de licencia y pasarlo a la propiedad IronPdf.License.LicenseKey.

using System.Configuration;

string licenseKey = ConfigurationManager.AppSettings ["IronPdf.LicenseKey"];

IronPdf.License.LicenseKey = licenseKey;
using System.Configuration;

string licenseKey = ConfigurationManager.AppSettings ["IronPdf.LicenseKey"];

IronPdf.License.LicenseKey = licenseKey;
Imports System.Configuration

Private licenseKey As String = ConfigurationManager.AppSettings ("IronPdf.LicenseKey")

IronPdf.License.LicenseKey = licenseKey
$vbLabelText   $csharpLabel