在 web.config 中配置 IronXL 授權(C#)

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

隨著 IronXL 版本 2024.3.20 的推出,問題已經解決了。

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

在舊版的IronXL中,特別是版本2023.4.132024.3.20之間,存在已知的授權問題:

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

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

變通方法

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

示例:

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

透過上方提供的 XML 檔案,我們可以使用ConfigurationManager來檢索授權金鑰值,並將其傳遞給IronXL.License.LicenseKey屬性。

using System.Configuration;

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

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

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

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

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

IronXL.License.LicenseKey = licenseKey
$vbLabelText   $csharpLabel