在Web.config中设置许可证密钥

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

自从 IronOCR 版本 2024.3.4 起,此问题已被解决

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

对于较旧版本的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>
<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