在 web.config 中設定 IronBarcode 許可證
Curtis Chau
已更新: 2026年8月2日
此問題已在IronBarcode的2024.3.2版本中解決。
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronBarcode must be licensed for development.
Text
對於舊版本的IronBarcode,特別是版本2023.4.1到2024.3.2之間,已知存在授權問題於:
- ASP.NET項目
- .NET Framework 版本 >= 4.6.2
存儲在Web.config文件中的金鑰將不會被產品拾取和使用。
解決方法
為了解決這個問題,建議在程式碼中使用ConfigurationManager從 Web.config 檔案中檢索授權金鑰,然後將其應用於 License.LicenseKey 屬性。
例子:
<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;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 = licenseKeyImports 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 = licenseKeyCurtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。