Configure a Licença IronXL no web.config (C#)

This article was translated from English: Does it need improvement?
Translated
View the article in English

O problema foi resolvido a partir da versão 2024.3.20 do IronXL.

Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronXL must be licensed for development.

Para versões mais antigas do IronXL, especificamente entre as versões 2023.4.13 e 2024.3.20 , existe um problema conhecido de licenciamento em:

  • Projetos ASP.NET
  • Versão do .NET Framework >= 4.6.2

A chave armazenada em um arquivo Web.config NÃO será captada e usada pelo produto.

Solução alternativa

Para resolver este problema, é recomendado recuperar a chave de licença do arquivo Web.config usando ConfigurationManager no código, e depois aplicá-la à propriedade License.LicenseKey.

Exemplo:

Abaixo está um exemplo de como armazenar a chave de licença em um arquivo 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

Com a configuração do arquivo XML acima, podemos usar ConfigurationManager para recuperar o valor da chave de licença e defini-lo para a propriedade 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

Neste exemplo, ConfigurationManager.AppSettings é usado para recuperar o valor de IronXL.LicenseKey de Web.config. A chave de licença recuperada é então configurada para IronXL.License.LicenseKey para garantir que os componentes do IronXL possam funcionar corretamente.

Curtis Chau
Redator Técnico

Curtis Chau é bacharel em Ciência da Computação (Universidade Carleton) e se especializa em desenvolvimento front-end, com experiência em Node.js, TypeScript, JavaScript e React. Apaixonado por criar interfaces de usuário intuitivas e esteticamente agradáveis, Curtis gosta de trabalhar com frameworks modernos e criar manuais ...

Leia mais
Pronto para começar?
Nuget Downloads 2,150,290 | Versão: 2026.7 recém-lançado
Still Scrolling Icon

Ainda está rolando a tela?

Quer provas rápidas? PM > Install-Package IronXL.Excel
executar um exemplo Veja seus dados se transformarem em uma planilha.