在web.config中配置IronXL授權(C#)
Curtis Chau
已更新: 2026年5月9日
問題已在IronXL版本2024.3.20中解決。
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronXL must be licensed for development.
Text
對於舊版的IronXL,特別是那些在版本2023.4.13和2024.3.20之間的版本,存在已知的授權問題:
- ASP.NET項目
- .NET Framework 版本 >= 4.6.2
儲存在Web.config檔案中的金鑰將不會被產品拾取和使用。
解決方法
為了解決此問題,建議從Web.config 檔案中使用ConfigurationManager 在程式碼中檢索授權金鑰,然後將其應用於License.LicenseKey 屬性。
例子:
以下是一個如何將授權金鑰存儲在Web.config檔案中的範例:
<configuration>
...
<appSettings>
<add key="IronXL.LicenseKey" value="IronXL-MYLICENSE-KEY-1EF01"/>
</appSettings>
...
</configuration>
XML
透過上述的XML檔案設置,我們可以使用ConfigurationManager來檢索授權金鑰的值,並將其設定到IronXL.License.LicenseKey屬性:
using System.Configuration;
// Retrieve the license key from the Web.config 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 = licenseKeyImports 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.config 檢索IronXL.LicenseKey 的值。 檢索到的授權金鑰然後被設定到IronXL.License.LicenseKey中,以確保IronXL元件能正確運作。
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。