在 web.config 中設定 IronBarcode 授權

2024年3月20日
已更新 2024年12月17日
分享:
This article was translated from English: Does it need improvement?
Translated
View the article in English

此問題已在 IronBarcode 的2024.3.2版本中解決。

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

在較舊版本的IronBarcode中,特別是2023.4.12024.3.2之間的版本,有一個已知的授權問題:

  • ASP.NET 項目
  • .NET Framework 版本 >= 4.6.2

    Web.config 檔案中儲存的密鑰不會被產品拾取或使用。

變通方法

要解決此問題,建議在程式碼中使用ConfigurationManagerWeb.config文件中檢索授權金鑰,然後將其應用於License.LicenseKey屬性。

示例:

<configuration>
...
  <appSettings>
    <add key="IronBarCode.LicenseKey" value="IRONBARCODE-MYLICENSE-KEY-1EF01"/>
  </appSettings>
...
</configuration>
XML

透過上述提供的 XML 文件,我們可以使用ConfigurationManager檢索授權密鑰值,並將其傳遞給IronBarCode.License.LicenseKey屬性。

using System.Configuration;

string licenseKey = ConfigurationManager.AppSettings ["IronBarCode.LicenseKey"];

IronBarCode.License.LicenseKey = licenseKey;
using System.Configuration;

string licenseKey = ConfigurationManager.AppSettings ["IronBarCode.LicenseKey"];

IronBarCode.License.LicenseKey = licenseKey;
Imports System.Configuration

Private licenseKey As String = ConfigurationManager.AppSettings ("IronBarCode.LicenseKey")

IronBarCode.License.LicenseKey = licenseKey
$vbLabelText   $csharpLabel