在 Web.config 中設置許可證密鑰

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

This problem has been solved since IronPDF version 2024.3.3.

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

對於較舊的 IronPDF 版本,特別是介於版本之間的那些 2023.4.42024.3.3在以下情況存在已知的授權問題:

  • ASP.NET 專案
  • .NET Framework 版本 >= 4.6.2

儲存在 Web.config 檔案中的密鑰 不會 被產品識別和使用。

解決方法

為了解決此問題,建議使用 ConfigurationManagerWeb.config 文件中獲取授權金鑰,然後應用於 License.LicenseKey 屬性。

範例:

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

透過上面提供的 XML 檔案,我們可以使用 ConfigurationManager 來檢索授權金鑰值並將其傳遞給 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
VB   C#