在 Web.config 中設定許可證金鑰
Curtis Chau
已更新: 2026年4月22日
此問題已在IronPDF版本2024.3.3中解決。
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronPDF must be licensed for development.
Text
對於較早的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
使用以上提供的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 ClassImports 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 ClassCurtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。