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