Setup barcode online generation streaming web service in ASP.NET
Here we will show how to set up a barcode generation streaming service in ASP.NET web server for ASP.NET Core and ASP.NET Framework.
After setup completes, you could generate barcodes using URL in web browser or other applications.
After setup completes, you could generate barcodes using URL in web browser or other applications.
Setup on IIS with ASP.NET Core
The following guide will create an ASP.NET Core Empty for Windows, which allows you to create QR Code and barcodes through URL.
Here are the requirements:
Here are the requirements:
- Visual Studio 2022
- .NET 6.0 SDK
- OnBarcode.Barcode.ASPNETCore.dll for Windows, or OnBarcode.Barcode.ASPNETCore.Skia.dll for Linux, MacOS, non-Windows
- Step 1: Create a new project with project template "ASP.NET Core Empty".
- Step 2: Choose framework .NET 6.0 (Long Term Support).
- Step 3: Add project reference: assembly "OnBarcode.Barcode.ASPNETCore.dll" or "OnBarcode.Barcode.ASPNETCore.Skia.dll" to the project.
- Step 4: For Windows: Install package "System.Drawing.Common" (Version 4.5.0 or later) by NuGet.
For Linux, MacOS, non-Windows: Install package "SkiaSharp" (Version 2.80.0 or later) by NuGet. - Step 5: Replace content in file "Program.cs" by below C# codes
var builder = WebApplication.CreateBuilder(args); builder.Services.AddHttpContextAccessor(); var app = builder.Build(); // Linear app.MapGet("/", async (IHttpContextAccessor httpContextAccessor) => { var context = httpContextAccessor.HttpContext; if (context != null) await OnBarcode.Barcode.ASPNETCore.LinearWebStream.drawBarcodeAsync(context.Request, context.Response); }); // PDF417 app.MapGet("/PDF417", async (IHttpContextAccessor httpContextAccessor) => { var context = httpContextAccessor.HttpContext; if (context != null) await OnBarcode.Barcode.ASPNETCore.PDF417WebStream.drawBarcodeAsync(context.Request, context.Response); }); // DataMatrix app.MapGet("/DataMatrix", async (IHttpContextAccessor httpContextAccessor) => { var context = httpContextAccessor.HttpContext; if (context != null) await OnBarcode.Barcode.ASPNETCore.DataMatrixWebStream.drawBarcodeAsync(context.Request, context.Response); }); // QRCode app.MapGet("/QRCode", async (IHttpContextAccessor httpContextAccessor) => { var context = httpContextAccessor.HttpContext; if (context != null) await OnBarcode.Barcode.ASPNETCore.QRCodeWebStream.drawBarcodeAsync(context.Request, context.Response); }); // MicroPDF417 app.MapGet("/MicroPDF417", async (IHttpContextAccessor httpContextAccessor) => { var context = httpContextAccessor.HttpContext; if (context != null) await OnBarcode.Barcode.ASPNETCore.MicroPDF417WebStream.drawBarcodeAsync(context.Request, context.Response); }); // MicroQRCode app.MapGet("/MicroQRCode", async (IHttpContextAccessor httpContextAccessor) => { var context = httpContextAccessor.HttpContext; if (context != null) await OnBarcode.Barcode.ASPNETCore.MicroQRCodeWebStream.drawBarcodeAsync(context.Request, context.Response); }); app.Run();
- Step 6: Run the demo project (Press Ctrl+F5).
- Step 7: You can send barcode settings through URL as below.
Eg. Default is Linear barcode
https://localhost:7158/?DATA=12345678&X=3
https://localhost:7158/QRCode?DATA=12345678&X=10
https://localhost:7158/MicroPDF417?DATA=123&X=2
Setup on IIS with .NET Framework
- Copy barcode folder and its contents from the downloaded package to your IIS.
- If the ASP.NET is using .NET Framework 4.x, copy dll file OnBarcode.Barcode.ASPNET.dll from {downloaded package}/dll/Net40/ to folder barcode/Bin
- If the ASP.NET is using .NET Framework 2.x or 3.x, copy dll file OnBarcode.Barcode.ASPNET.dll from {downloaded package}/dll/Net20/ to folder barcode/Bin
- Create a new virtual directory in IIS manager and name it barcode.
- Restart IIS
- Open web browser, navigate to: http://YourDomain:Port/barcode/qrcode.aspx?DATA=9876543210, you will view a QR Code generated in browser.
Integrate barcode web streaming in your applications
Integrating the OnBarcode barcode streaming service into your applications is really a simple task.
What you need do is to pass our dynamic barcode image generation URL to your web pages IMG tag, or to your reporting and business appliations that are supporting loading and rendering image through URL.
What you need do is to pass our dynamic barcode image generation URL to your web pages IMG tag, or to your reporting and business appliations that are supporting loading and rendering image through URL.
Using ASP.NET Core web service
- Dynamic barcode image URL for 1D / Linear barcodes: http://localhost:[port]/?DATA=12345678&X=3
- Dynamic barcode image URL for Data Matrix barcodes: http://localhost:[port]/DataMatrix?Data=123ABC
- Dynamic barcode image URL for PDF-417 barcodes: http://localhost:[port]/PDF417?Data=123ABC
- Dynamic barcode image URL for Micro PDF-417 barcodes: http://localhost:[port]/MicroPDF417?Data=123ABC
- Dynamic barcode image URL for QR Code barcodes: http://localhost:[port]/QRCode?Data=123ABC
- Dynamic barcode image URL for Micro QR Code barcodes: http://localhost:[port]/MicroQRCode?Data=123ABC
ASP.NET Framework web service
- Dynamic barcode image URL for 1D / Linear barcodes: http://localhost:[port]/barcode/linear.aspx?DATA=12345678&X=3
- Dynamic barcode image URL for Data Matrix barcodes: http://localhost:[port]/barcode/datamatrix.aspx?Data=123ABC
- Dynamic barcode image URL for PDF-417 barcodes: http://localhost:[port]/barcode/pdf417.aspx?Data=123ABC
- Dynamic barcode image URL for Micro PDF-417 barcodes: http://localhost:[port]/barcode/micro-pdf417.aspx?Data=123ABC
- Dynamic barcode image URL for QR Code barcodes: http://localhost:[port]/barcode/qrcode.aspx?Data=123ABC
- Dynamic barcode image URL for Micro QR Code barcodes: http://localhost:[port]/barcode/micro-qrcode.aspx?Data=123ABC
C#.NET Barcode all supported barcode formats
.NET Barcode Control DLL for C# - Barcodes Generation
- .NET 1D / Linear Barcodes:
- .NET 2D / Matrix Barcodes: .NET Data Matrix, .NET PDF-417, .NET QR Code, .NET Micro PDF-417, .NET Micro QR Code
