Can I Run IronBarcode with .NET on Azure?

Yes! IronBarcode can be used to read and write QR/barcodes in .NET applications hosted on Azure services. IronBarcode has been thoroughly tested on multiple Azure platforms including MVC websites, Azure Functions, and many more.


Pre-requisites

1. Install IronBarcode to Get Started

First, install the NuGet package on the NuGet website.

Install-Package BarCode

As an alternative, the IronBarcode.dll could also be downloaded and added to your project.


How to Tutorial

2. Performance and Azure Tiers

We recommend at least using the Azure B1 service plan, as it's suitable for most of our users' use cases. Systems that require higher throughput will need a higher service plan.

3. Framework Choice

.NET Standard, Core, and Framework projects are all compatible with IronBarcode.

4. Docker on Azure

One way to gain the ability to control performance and stability with IronBarcode on Azure is to use Docker. To learn how to use IronBarcode with Azure and Docker, have a look at this tutorial.

5. Official Azure Function Support

IronBarcode currently supports Azure Functions V3 and V4.

Working Azure Function Code Example

Tested on Azure Functions v3.3.1.0+. Here is a code sample:

using System;
using System.Net;
using System.Net.Http;
using IronBarCode;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;

public static class BarcodeFunction
{
    // Azure Function triggered by HTTP request.
    [FunctionName("barcode")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        // Set the license key for IronBarcode if needed.
        IronBarCode.License.LicenseKey = "Key";

        // Create a QR barcode from a string.
        var myBarCode = BarcodeWriter.CreateBarcode("IronBarcode Test", BarcodeEncoding.QRCode);

        // Prepare the HTTP response to return the barcode image.
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(myBarCode.ToJpegBinaryData())
        };

        // Set content headers for attachment and content type.
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        { 
            FileName = $"{DateTime.Now:yyyyMMddmm}.jpg" 
        };

        response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");

        return response;
    }
}
using System;
using System.Net;
using System.Net.Http;
using IronBarCode;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;

public static class BarcodeFunction
{
    // Azure Function triggered by HTTP request.
    [FunctionName("barcode")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        // Set the license key for IronBarcode if needed.
        IronBarCode.License.LicenseKey = "Key";

        // Create a QR barcode from a string.
        var myBarCode = BarcodeWriter.CreateBarcode("IronBarcode Test", BarcodeEncoding.QRCode);

        // Prepare the HTTP response to return the barcode image.
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(myBarCode.ToJpegBinaryData())
        };

        // Set content headers for attachment and content type.
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        { 
            FileName = $"{DateTime.Now:yyyyMMddmm}.jpg" 
        };

        response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");

        return response;
    }
}
$vbLabelText   $csharpLabel

In this code:

  • We define an Azure Function with the name "barcode."
  • The function is triggered by an HTTP request and logs a message when processed.
  • We specify the license key for IronBarcode (replace "Key" with your actual license key).
  • A QR code barcode is generated using BarcodeWriter.CreateBarcode.
  • The barcode image is converted to JPEG format and included in the HTTP response.
  • The response content is set as a downloadable attachment with the current date and time as the file name.
  • The response content type is set to "image/jpeg" to indicate the image format.

Frequently Asked Questions

Can I run IronBarcode with .NET on Azure?

Yes, IronBarcode can be used to read and write QR/barcodes in .NET applications hosted on Azure services. It has been tested on multiple Azure platforms including MVC websites and Azure Functions.

What are the prerequisites for using IronBarcode on Azure?

To get started, you need to install the IronBarcode NuGet package using the command: `dotnet add package IronBarCode`. Alternatively, you can download the IronBarcode.dll and add it to your project.

Which Azure service plan is recommended for IronBarcode?

We recommend using at least the Azure B1 service plan for most use cases. Systems requiring higher throughput should consider a higher service plan.

Which .NET frameworks are compatible with IronBarcode?

.NET Standard, Core, and Framework projects are all compatible with IronBarcode.

How can I use Docker with IronBarcode on Azure?

You can enhance performance and stability by using Docker on Azure. Refer to the provided tutorial for detailed steps on integrating IronBarcode with Azure and Docker.

Does IronBarcode support Azure Functions?

Yes, IronBarcode supports Azure Functions V3 and V4. A working code example is provided for Azure Functions v3.3.1.0+.

What does the Azure Function code example for IronBarcode do?

The example defines an Azure Function triggered by an HTTP request to generate a QR code. It logs a message, sets a license key, creates a QR code, and returns the barcode image as a JPEG in the HTTP response.