在 Web.config 中设置许可密钥

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

自 IronPDF 版本 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 属性。

Example:

<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

通过上面提供的 XML 文件,我们可以使用 ConfigurationManager 来检索许可密钥值,并将其传递给 IronPdf.License.LicenseKey 属性。

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
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 16,493,056 | Version: 2025.11 刚刚发布