Streaming QR Code Image into Your ASP.NET Web Pages
- Under downloaded trial package, copy barcode folder and its contents to your IIS, and create a new virtual directory, named "barcode".
- Restart IIS, navigate to http://YourDomain:Port/barcode/qrcode.aspx?DATA=0123456789.
- To create barcode image in html or aspx pages, you can insert a image tag (img) into your web pages.
For example, <img src="http://YourDomain:Port/barcode/qrcode.aspx?DATA=0123456789" />
Generate QR Code into Your ASP.NET Web Forms
- Install ASP.NET Barcode Generator Control.
- Add ASP.NET Barcode Generator Control to your Visual Studio ToolBox.
- Copy "qrcode.aspx" and "qrcode.aspx.cs" to the folder where your aspx pages are generating barcodes.
- Drag and drop "QRCodeWebForm" to your ASPX web forms.
- Run the website to view the barcodes generated. To customize QR Code settings, view QR Code barcode settings.
Generate QR Code Barcodes in ASP.NET Class
If you need generate QR Code barcodes in your ASP.NET class using C# or VB.NET, we provides complete barcode generation source code for QR Code in C# and QR Code in VB.NET.
Key Concepts of QR Code Encoding in ASP.NET
To generate QR Codes effectively in ASP.NET projects, it is important to understand the key encoding concepts, including supported character sets, data modes, and maximum data length. These concepts ensure that the QR Code is encoded correctly and meets your web project requirements.
QR Code Encodable Character Set
QR Code supports multiple data formats, which can be used in ASP.NET projects to encode different types of information. The supported character sets are:
- Numbers (digits 0-9): Suitable for encoding numeric data such as IDs or phone numbers.
- ASCII characters (plain text): Includes standard printable characters (A-Z, a-z, 0-9, and special characters).
- Unicode text: Supports international characters (e.g., Arabic, Greek, Thai) when encoded properly.
- Byte data: Defaults to the ISO/IEC 8859-1 character set, but can be configured to use other character sets.
- Kanji characters: Japanese characters that can be compacted into 13 bits for efficient encoding.
QR Code Data Mode
QR Code uses different data modes to encode data efficiently. The C# Barcode Generator library provides five data mode options, which can be set in your ASP.NET project code. The data mode is automatically selected by default, but you can specify it manually for specific use cases.
The five data modes (QRCodeDataMode) are:
The five data modes (QRCodeDataMode) are:
- QRCodeDataMode.Auto: The Barcode library automatically selects the most efficient data mode based on the input data (recommended for most ASP.NET use cases).
- QRCodeDataMode.Numeric: For encoding numeric data only (digits 0-9), which is more efficient than other modes for numeric content.
- QRCodeDataMode.AlphaNumeric: For alphanumeric data, including digits 0-9, uppercase letters A-Z, and nine special characters (space, $ % * + - . / :).
- QRCodeDataMode.Byte: For byte data, which is used for encoding Unicode text, binary data, or non-ASCII characters.
- QRCodeDataMode.Kanji: For encoding Kanji characters (Japanese), which are compacted into 13 bits to save space.
Maximum Data Length in QR Code
The maximum number of characters that can be encoded in a QR Code depends on the data mode and QR Code version (Version 40-L is the largest). In ASP.NET projects, this is important when encoding large amounts of data (e.g., in a Web API response).
- Numeric data: 7,089 characters (Version 40-L).
- Alphanumeric data: 4,296 characters (Version 40-L).
- Byte data: 2,953 characters (Version 40-L).
- Kanji data: 1,817 characters (Version 40-L).
Generate QR Code with Various Text Formats in ASP.NET
ASP.NET projects often need to encode different text formats into QR Codes, such as non-printable ASCII characters, Unicode text, GS1 data, and Kanji text. The following sections provide step-by-step instructions for each text string format with sample code.
Generate QR Code with ASCII Non-Printable Characters
ASCII non-printable characters (e.g., Carriage Return [CR], Line Feed [LF]) are control characters that do not have visible labels. To encode these characters in a QR Code in your ASP.NET project, you need to enable the ProcessTilde property and convert the character to its three-digit ASCII value.
Note: Ensure the three-digit ASCII value is padded with leading zeros if necessary (e.g., ASCII value 5 becomes ~005, not ~5).
- Create a new QRCode object in your ASP.NET Controller or Page Model.
- Set ProcessTilde to true to enable the use of "~" in the data message (used to represent non-printable characters).
- Set DataMode to QRCodeDataMode.Auto.
- Set the Data property to "~ddd", where "ddd" is the three-digit ASCII value of the non-printable character (e.g., ~013 for [CR]).
- Call drawBarcode() to save the QR Code to a specified path in your ASP.NET project
Note: Ensure the three-digit ASCII value is padded with leading zeros if necessary (e.g., ASCII value 5 becomes ~005, not ~5).
Encode Unicode Text in QR Code
QR Code does not support Unicode text (e.g., Thai, Arabic, Greek) by default. In ASP.NET projects, you can encode Unicode text by converting it to a byte array using UTF-8 encoding and using the Byte data mode.
- Create a new QRCode object in your ASP.NET Controller or Page Model.
- Set ProcessTilde to true to enable the use of "~" in the data message.
- Set DataMode to QRCodeDataMode.Byte.
- Convert the Unicode text to a byte array using UTF-8 encoding, then convert each byte to a three-digit string prefixed with "~".
- Set the Data property to the combined string of these three-digit values.
- Call drawBarcode() to save the QR Code to a specified path.
Generate GS1 QR Code in ASP.NET
GS1 QR Code is a specialized QR Code format used to encode GS1 data elements (e.g., product IDs, expiration dates) in compliance with GS1 standards. In ASP.NET projects, you can generate GS1 QR Code by setting the FNC1 property and formatting the data with Application Identifier (AI) codes.
Note: Ensure the AI codes are correctly formatted (enclosed in parentheses) and the data length matches the requirements for each AI code.
- Create a new QRCode object in your ASP.NET project.
- Set FNC1 to FNC1.FNC1_1ST_POS to enable GS1 mode.
- Set DataMode to QRCodeDataMode.Auto.
- Set the Data property to the GS1 data string, where each AI code is enclosed in parentheses followed by the corresponding data (e.g., "(17)050101(10)ABC123").
- Call drawBarcode() to save the GS1 QR Code to a specified path.
Note: Ensure the AI codes are correctly formatted (enclosed in parentheses) and the data length matches the requirements for each AI code.
Encode Binary Data in QR Code
Most 2D barcode symbologies, including QR Code, support binary data encoding. In ASP.NET projects, you can encode binary data (e.g., file contents, serialized objects) using the C# Barcode Generator library. The process is similar to encoding Unicode text, as binary data is converted to a byte array.
Encode Kanji Text in QR Code
Kanji text (Japanese characters) can be encoded in QR Code using the Kanji data mode, which compacts each character into 13 bits. In ASP.NET projects, you need to enable the ProcessTilde property and convert Kanji characters to their decimal equivalent in the JIS X 0208 standard.
- Create a new QRCode object in your ASP.NET project.
- Set ProcessTilde to true to enable the use of "~" in the data message.
- Set DataMode to QRCodeDataMode.Kanji.
- Set the Data property to "~9ddddd", where "ddddd" is the five-digit decimal value of the Kanji character (e.g., ~937727 for the Kanji character "点").
- Call drawBarcode() to save the QR Code to a specified path.
Customize QR Code Dimension Size in ASP.NET web app
You can customize the width (and height, as QR Code is square) of the QR Code image in your ASP.NET project using the BarcodeWidth property. This is useful for ensuring the QR Code is large enough to be scanned easily or fits within a specific UI element.
- Create a new QRCode object in your ASP.NET Controller or Page Model.
- Set the Data property to the desired data message.
- Set the BarcodeWidth property to the desired width (e.g., 200 pixels).
- Call drawBarcode() to save the customized QR Code to a specified path.
Set QR Code Quiet Zone
The quiet zone is a blank area surrounding the QR Code that is required for scanners to detect the QR Code correctly. In ASP.NET projects, you can set the quiet zone using four properties: LeftMargin, RightMargin, TopMargin, and BottomMargin.
Note: The recommended quiet zone for QR Code is at least 4 modules (pixels) on all sides. Adjust the margin values based on your project's requirements.
Note: The recommended quiet zone for QR Code is at least 4 modules (pixels) on all sides. Adjust the margin values based on your project's requirements.
Advanced QR Code Features in ASP.NET Projects
ASP.NET projects may require advanced QR Code settings to meet specific functional requirements, such as error correction, version control, Structured Append mode, FNC1 mode, and ECI mode. The following sections cover these advanced settings.
QR Code Error Correction Mode
QR Code uses Reed-Solomon error correction to recover data if the QR Code is damaged or obscured. There are four error correction levels (L, M, Q, H), which determine the percentage of data that can be recovered. In ASP.NET projects, you can set the error correction level using the ECL property.
- QRCodeECL.L: 7% data recovery (default, suitable for most ASP.NET use cases).
- QRCodeECL.M: 15% data recovery (recommended for environments where the QR Code may be slightly damaged).
- QRCodeECL.Q: 25% data recovery (suitable for harsh environments).
- QRCodeECL.H: 30% data recovery (highest level, used for critical data).
QR Code Version
QR Code has 40 versions (Version 1 to Version 40), with each version increasing in size and data capacity. In ASP.NET projects, you can set the QR Code version using the Version property (from QRCodeVersion.V1 to QRCodeVersion.V40).
Note: If you do not specify a version, the library will automatically select the smallest version that can accommodate the data.
Note: If you do not specify a version, the library will automatically select the smallest version that can accommodate the data.
QR Code FNC1 in First Position
FNC1 (Function Character 1) in the first position indicates that the QR Code encodes data formatted according to GS1 standards.
This is the same as the GS1 QR Code mode learned early. In ASP.NET projects, you can enable this mode by setting the FNC1 property to FNC1.FNC1_1ST_POS.
Summary
This page provides a comprehensive guide of generating and customizing QR Code in ASP.NET projects using C# and a C# Barcode Generator library. It covers basic QR Code generation, data encoding rules, various text format support, image customization, and advanced settings.
