Ustawianie klucza licencyjnego w 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.

Dla starszych wersji IronOCR, szczególnie tych pomiędzy wersjami 2023.4.13 i 2024.3.4, występuje znany problem licencjonowania w:

  • projektach ASP.NET
  • wersjach .NET Framework >= 4.6.2

The key stored in a Web.config file will NOT be picked up and used by the product.

Obejscie problemu

To address this issue, it is recommended to retrieve the license key from the Web.config file using ConfigurationManager in the code, and then apply it to the License.LicenseKey property.

Przykład:

<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

Z dostarczonym powyżej plikiem XML możemy użyć ConfigurationManager, aby pobrać wartość klucza licencyjnego i przekazać ją do właściwości 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;
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 = licenseKey
$vbLabelText   $csharpLabel
Curtis Chau
Autor tekstów technicznych

Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podrę...

Czytaj więcej
Gotowy, aby rozpocząć?
Nuget Pliki do pobrania 5,896,332 | Wersja: 2026.5 just released
Still Scrolling Icon

Wciąż przewijasz?

Czy chcesz szybko dowodu? PM > Install-Package IronOcr
uruchom próbkę obserwuj, jak twój obraz staje się tekstem z możliwością wyszukiwania.