web.co/nfig 中的 IronOCR 授權設定
This article was translated from English: Does it need improvement?
Translated
View the article in English
此問題已於 IronZip 版本 2024.3.3 解決。
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronZip must be licensed for development.
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronZip must be licensed for development.
SHELL
針對較舊的 IronZip 版本,特別是 2024.3.3 版本之前發佈的版本,存在已知的授權問題:
- ASP.NET 專案
- .NET Framework 版本 >= 4.6.2
儲存於 Web.co/nfig 檔案中的金鑰,將不會被產品讀取並使用。
解決方案
為解決此問題,建議在程式碼中使用 ConfigurationManager 從 Web.co/nfig 檔案中擷取授權金鑰,然後將其套用至 License.LicenseKey 屬性。
範例:
<configuration>
...
<appSettings>
<add key="IronZip.LicenseKey" value="IRONZIP.MYLICENSE.KEY.1EF01"/>
</appSettings>
...
</configuration>
<configuration>
...
<appSettings>
<add key="IronZip.LicenseKey" value="IRONZIP.MYLICENSE.KEY.1EF01"/>
</appSettings>
...
</configuration>
XML
透過上述提供的 XML 檔案,我們可以使用 ConfigurationManager 擷取授權金鑰值,並將其傳遞給 IronZip.License.LicenseKey 屬性。
using System;
using System.Co/nfiguration;
class Program
{
static void Main()
{
// Retrieve the license key from the web.co/nfig appSettings
string licenseKey = ConfigurationManager.AppSettings["IronZip.LicenseKey"];
// Apply the license key to IronZip
IronZip.License.LicenseKey = licenseKey;
// Verify that the license key is set properly
Console.WriteLine("License key applied successfully.");
}
}
using System;
using System.Co/nfiguration;
class Program
{
static void Main()
{
// Retrieve the license key from the web.co/nfig appSettings
string licenseKey = ConfigurationManager.AppSettings["IronZip.LicenseKey"];
// Apply the license key to IronZip
IronZip.License.LicenseKey = licenseKey;
// Verify that the license key is set properly
Console.WriteLine("License key applied successfully.");
}
}
Imports System
Imports System.Configuration
Module Program
Sub Main()
' Retrieve the license key from the web.config appSettings
Dim licenseKey As String = ConfigurationManager.AppSettings("IronZip.LicenseKey")
' Apply the license key to IronZip
IronZip.License.LicenseKey = licenseKey
' Verify that the license key is set properly
Console.WriteLine("License key applied successfully.")
End Sub
End Module
$vbLabelText
$csharpLabel
using System.Co/nfiguration;指令可存取設定檔,例如Web.co/nfig。ConfigurationManager.AppSettings["IronZip.LicenseKey"]會從appSettings區段中讀取Web.co/nfig所儲存的授權金鑰。IronZip.License.LicenseKey = licenseKey;會將擷取到的金鑰指派給 IronZIP程式庫,以避免觸發授權例外狀況。Console.WriteLine()語句會向開發人員回報,表示授權金鑰申請流程已成功完成。
準備開始了嗎?
Nuget 下載 21,060 | 版本: 2026.6 just released

