在 Web.config 中設定授權金鑰
2024年3月19日
已更新 2024年10月20日
This article was translated from English: Does it need improvement?
TranslatedView the article in English
此問題自 IronOCR 版本 2024.3.4 起已解決。
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronOCR must be licensed for development.
對於較舊版本的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;
string licenseKey = ConfigurationManager.AppSettings ["IronOcr.LicenseKey"];
IronOcr.License.LicenseKey = licenseKey;
using System.Configuration;
string licenseKey = ConfigurationManager.AppSettings ["IronOcr.LicenseKey"];
IronOcr.License.LicenseKey = licenseKey;
Imports System.Configuration
Private licenseKey As String = ConfigurationManager.AppSettings ("IronOcr.LicenseKey")
IronOcr.License.LicenseKey = licenseKey
$vbLabelText $csharpLabel