在web.config(C#)中配置IronXL授權
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.
對於舊版IronXL,特別是版本2023.4.13至2024.3.20之間的版本,已知在以下情況存在授權問題:
- ASP.NET專案
- .NET Framework version >= 4.6.2
儲存在Web.config文件中的金鑰將無法被產品拾取並使用。
替代方案
為了解決此問題,建議從License.LicenseKey屬性。
範例:
以下是如何在Web.config文件中儲存授權金鑰的範例:
<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;
// 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;
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
Private licenseKey As String = ConfigurationManager.AppSettings("IronXL.LicenseKey")
' Apply the retrieved license key to the IronXL component
IronXL.License.LicenseKey = licenseKey
$vbLabelText
$csharpLabel
在此範例中,使用IronXL.LicenseKey的值。 然後將擷取的授權金鑰設置到IronXL.License.LicenseKey中,以確保IronXL元件能夠正常運行。
準備好開始了嗎?
Nuget 下載 2,134,203 | 版本: 2026.7 剛剛發布

