在 Web.config 中設定許可證金鑰
Curtis Chau
已更新: 2026年7月6日
此問題已在IronQR版本2024.3.2中解決。
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronQR must be licensed for development.
Text
對於舊版的IronQR,特別是版本2024.3.2之前發布的版本,已知在以下情況中存在授權問題:
- ASP.NET項目
- .NET Framework 版本 >= 4.6.2
儲存在Web.config檔案中的金鑰將不會被產品偵測到或使用。
解決方法
為了解決此問題,建議在程式碼中使用ConfigurationManager從Web.config檔案中檢索授權金鑰,然後將其應用於License.LicenseKey屬性。
例子:
<configuration>
...
<appSettings>
<add key="IronQR.LicenseKey" value="IronQR-MYLICENSE-KEY-1EF01"/>
</appSettings>
...
</configuration>
XML
使用上述提供的XML檔案,我們可以使用ConfigurationManager檢索授權金鑰值,並將其傳遞到IronQr.License.LicenseKey屬性。
using System.Configuration;
// Retrieve the license key from the Web.config file's appSettings section
string licenseKey = ConfigurationManager.AppSettings["IronQR.LicenseKey"];
// Apply the retrieved license key to the IronQR LicenseKey property
IronQr.License.LicenseKey = licenseKey;Imports System.Configuration
' Retrieve the license key from the Web.config file's appSettings section
Dim licenseKey As String = ConfigurationManager.AppSettings("IronQR.LicenseKey")
' Apply the retrieved license key to the IronQR LicenseKey property
IronQr.License.LicenseKey = licenseKeyImports System.Configuration
' Retrieve the license key from the Web.config file's appSettings section
Dim licenseKey As String = ConfigurationManager.AppSettings("IronQR.LicenseKey")
' Apply the retrieved license key to the IronQR LicenseKey property
IronQr.License.LicenseKey = licenseKeyCurtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。