在 Web.config 中設定授權金鑰
此問題已於 IronPDF 2024.3.3 版本中解決。
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronPDF must be licensed for development.
針對較舊的 IronPDF 版本,特別是 2023.4.4 至 2024.3.3 之間的版本,存在已知授權問題:
- ASP.NET 專案
- .NET Framework 版本 >= 4.6.2
儲存於 Web.config 檔案中的金鑰,產品將不會讀取並使用。
解決方案
為解決此問題,建議在程式碼中使用 ConfigurationManager 從 Web.config 檔案中擷取授權金鑰,然後將其套用至 License.LicenseKey 屬性。
範例:
<configuration>
...
<appSettings>
<add key="IronPdf.LicenseKey" value="IRONPDF-MYLICENSE-KEY-1EF01"/>
</appSettings>
...
</configuration>
透過上述提供的 XML 檔案,我們可以使用 ConfigurationManager 擷取授權金鑰值,並將其傳遞給 IronPdf.License.LicenseKey 屬性。
using System.Configuration;
class Program
{
static void Main()
{
// Retrieve the license key from the Web.config file
string licenseKey = ConfigurationManager.AppSettings["IronPdf.LicenseKey"];
// Apply the license key to the IronPdf library
IronPdf.License.LicenseKey = licenseKey;
// Additional processing can continue here
}
}Imports System.Configuration
Class Program
Shared Sub Main()
' Retrieve the license key from the Web.config file
Dim licenseKey As String = ConfigurationManager.AppSettings("IronPdf.LicenseKey")
' Apply the license key to the IronPdf library
IronPdf.License.LicenseKey = licenseKey
' Additional processing can continue here
End Sub
End Class
Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.