IronZIP授權在web.config中的設置

Curtis Chau
Curtis Chau
已更新: 2026年7月21日

此問題已知會影響IronZIP在2024.3.3之前發布的版本。

請注意: 那個版本的發佈說明並未特別列出Web.config/appSettings授權修正,所以如果您使用的是2024.3.3或更高版本但仍看到此異常,以下的變通方法仍然適用。
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.config文件中的金鑰將不會被產品檢測到和使用。

解決方法

為了解決此問題,建議使用ConfigurationManager在代碼中從Web.config文件中檢索授權金鑰,然後將其應用於License.LicenseKey屬性。

例子:

<configuration>
  ...
  <appSettings>
    <add key="IronZip.LicenseKey" value="IRONZIP.MYLICENSE.KEY.1EF01"/>
  </appSettings>
  ...
</configuration>
XML

使用上面提供的 XML 文件,我們可以使用ConfigurationManager檢索許可證金鑰值並將其傳遞給IronZip.License.LicenseKey屬性。

using System;
using System.Configuration;

class Program
{
    static void Main()
    {
        // Retrieve the license key from the web.config 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.Configuration; 指令允許存取配置檔案,如 Web.config。
  • ConfigurationManager.AppSettings["IronZip.LicenseKey"] 取得儲存在 appSettings 區段的 Web.config 授權金鑰。
  • IronZip.License.LicenseKey = licenseKey;將檢索到的金鑰分配給IronZIP程式庫以避免授權例外。
  • Console.WriteLine()語句向開發者提供反饋,表示授權金鑰應用過程已成功完成。

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

閱讀更多

準備好開始了嗎?

NuGet 下載次數 25,625版本:2026.11剛剛發布