Lizenzschlüssel in Web.config festlegen

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

Dieses Problem ist gelöst seit IronPDF Version 2024.3.3.

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

Für ältere IronPDF-Versionen, insbesondere zwischen den Versionen 2023.4.4 und 2024.3.3, gibt es ein bekanntes Lizenzproblem bei:

  • ASP.NET-Projekten
  • .NET Framework Version >= 4.6.2

Der in einer Web.config-Datei gespeicherte Schlüssel wird vom Produkt NICHT erfasst und verwendet.

Workaround

Um dieses Problem zu beheben, wird empfohlen, den Lizenzschlüssel mithilfe von ConfigurationManager im Code aus der Datei Web.config abzurufen und ihn dann auf die Eigenschaft License.LicenseKey anzuwenden.

Beispiel:

<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

Mit der oben bereitgestellten XML-Datei können wir ConfigurationManager verwenden, um den Lizenzschlüsselwert abzurufen und an die IronPdf.License.LicenseKey-Eigenschaft zu übergeben.

using System.Configuration;

class Program
{
    static void Main()
    {
        // Retrieve the license key from the Web.config file
        string licenseKey = ConfigurationManager.AppSettings["IronPdf.LicenseKey"];

        // Apply the license key to the IronPdf library
        IronPdf.License.LicenseKey = licenseKey;

        // Additional processing can continue here
    }
}
using System.Configuration;

class Program
{
    static void Main()
    {
        // Retrieve the license key from the Web.config file
        string licenseKey = ConfigurationManager.AppSettings["IronPdf.LicenseKey"];

        // Apply the license key to the IronPdf library
        IronPdf.License.LicenseKey = licenseKey;

        // Additional processing can continue here
    }
}
Imports System.Configuration

Friend Class Program
	Shared Sub Main()
		' Retrieve the license key from the Web.config file
		Dim licenseKey As String = ConfigurationManager.AppSettings("IronPdf.LicenseKey")

		' Apply the license key to the IronPdf library
		IronPdf.License.LicenseKey = licenseKey

		' Additional processing can continue here
	End Sub
End Class
$vbLabelText   $csharpLabel
Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen
Bereit anzufangen?
Nuget Downloads 19,014,616 | Version: 2026.5 just released
Still Scrolling Icon

Scrollst du immer noch?

Sie brauchen schnell einen Beweis? PM > Install-Package IronPdf
Führen Sie eine Probe aus Sehen Sie zu, wie Ihr HTML-Code in eine PDF-Datei umgewandelt wird.