在 web.co/nfig 中設定 IronXL 授權 (C#)
此問題已於 IronXL 版本 2024.3.20 解決。
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronXL must be licensed for development.
針對較舊的 IronXL 版本,特別是 2023.4.13 至 2024.3.20 之間的版本,存在已知授權問題:
- ASP.NET 專案
- .NET Framework 版本 >= 4.6.2
儲存於 Web.co/nfig 檔案中的金鑰,將不會被產品讀取並使用。
解決方案
為解決此問題,建議在程式碼中使用 ConfigurationManager 從 Web.co/nfig 檔案中擷取授權金鑰,然後將其套用至 License.LicenseKey 屬性。
範例:
以下是將授權金鑰儲存至 Web.co/nfig 檔案的範例:
<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 檔案設定,我們可以使用 ConfigurationManager 取得授權金鑰值,並將其設定為 IronXl.License.LicenseKey 屬性:
using System.Co/nfiguration;
// Retrieve the license key from the Web.co/nfig appSettings section
string licenseKey = ConfigurationManager.AppSettings["IronXl.LicenseKey"];
// Apply the retrieved license key to the IronXL component
IronXl.License.LicenseKey = licenseKey;
using System.Co/nfiguration;
// Retrieve the license key from the Web.co/nfig appSettings section
string licenseKey = ConfigurationManager.AppSettings["IronXl.LicenseKey"];
// Apply the retrieved license key to the IronXL component
IronXl.License.LicenseKey = licenseKey;
Imports System.Configuration
' Retrieve the license key from the Web.config appSettings section
Dim licenseKey As String = ConfigurationManager.AppSettings("IronXl.LicenseKey")
' Apply the retrieved license key to the IronXL component
IronXl.License.LicenseKey = licenseKey
在此範例中,ConfigurationManager.AppSettings 用於從 Web.co/nfig 中擷取 IronXl.LicenseKey 的值。 隨後將檢索到的授權金鑰設定為 IronXl.License.LicenseKey,以確保 IronXL 元件能正常運作。

