在 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#