IronBarcode License Setup in web.config

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

此問題已在2024.3.2版本的IronBarcode中解決。

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

For older IronBarcode versions, specifically those between versions 2023.4.1 and 2024.3.2, there is a known licensing issue in:

  • ASP.NET 項目
  • .NET Framework 版本 >= 4.6.2

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

解決方法

為了解決此問題,建議在代碼中使用 ConfigurationManagerWeb.config 文件中提取 License Key,然後將其應用於 License.LicenseKey 屬性。

範例:

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

使用上面提供的XML文件,我們可以使用ConfigurationManager來檢索授權密鑰值,並將其傳遞給IronBarCode.License.LicenseKey屬性。

using System.Configuration;
// Retrieve the license key from appSettings in the Web.config file
string licenseKey = ConfigurationManager.AppSettings["IronBarCode.LicenseKey"];

// Apply the retrieved license key to the IronBarCode LicenseKey property
IronBarCode.License.LicenseKey = licenseKey;
using System.Configuration;
// Retrieve the license key from appSettings in the Web.config file
string licenseKey = ConfigurationManager.AppSettings["IronBarCode.LicenseKey"];

// Apply the retrieved license key to the IronBarCode LicenseKey property
IronBarCode.License.LicenseKey = licenseKey;
Imports System.Configuration
' Retrieve the license key from appSettings in the Web.config file
Private licenseKey As String = ConfigurationManager.AppSettings("IronBarCode.LicenseKey")

' Apply the retrieved license key to the IronBarCode LicenseKey property
IronBarCode.License.LicenseKey = licenseKey
$vbLabelText   $csharpLabel
Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 1,935,276 | 版本: 2025.11 剛剛發布