在 Web.config 中設定授權金鑰

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

This problem has been solved since IronOCR version 2024.3.4.

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

對於舊版本的 IronOCR,特別是那些介於版本之間的2023.4.132024.3.4,已知存在授權問題於:

  • ASP.NET 專案
  • .NET Framework 版本 >= 4.6.2

    儲存在 Web.config 檔案中的金鑰不會被產品檢索和使用。

變通方法

要解決此問題,建議在程式碼中使用 ConfigurationManagerWeb.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
VB   C#