Writing Web Applications

CONTENTS:
  1. Overview
  2. Using directly Barcode.aspx or BarcodeHandler
  3. Using the web server control BarcodeImage

OVERVIEW

For web applications, Barcode .Net is a dynamic image generator. The generated images can be sent directly to the requesting browser without going through a file. Images can be generated in any format (gif, png, jpeg, etc.) that's supported by the .Net Framework,

Barcode .Net provides two ways for you to use this image generation function, through the use of the Barcode.aspx file or the HTTP handler BarcodeHandler, as in,

<img src="/Barcode.Net/Barcode.aspx">
<img src="BarcodeHandler.aspx">
where Barcode.Net is assumed to be the name of your application's virtual directory.

To provide better design time support, the BarcodeImage web server control is also provided; it can be used the same way you would the ASP.NET Image web server control. All BarcodeImage does is generate the HTML <img> element automatically when it is processed on the server. So, indeed, this is just an indirect way of using Barcode.aspx or BarcodeHandler.

USING Barcode.aspx OR BarcodeHandler

First off, you can simply type

    http://localhost/Barcode.Net/Barcode.aspx
or 
    http://localhost/Barcode.Net/BarcodeHandler.aspx
in your browser's URL field and press enter (first replace Barcode.Net by the name of your application's virtual directory).

You should see this image,

This is is a good way of testing your environment as any error messages would show up in your browser in place of the image.

Typically, however, you would embed a barcode image in an HTML page by adding

<img src="/Barcode.Net/Barcode.aspx">
This should generate the same image as above.

To be useful, you'll need to specify your own barcode type and data for the barcode image. For example,

<img src="/Barcode.Net/Barcode.aspx?BarcodeType=UPCA&Data=07447079382">
would generate,

The above examples use the Barcode.aspx file to generate barcode images. Alternatively, you can also use BarcodeHandler. To do so, you just need to add a configuration entry to your web application's ASP.NET configuration file (Web.config):

<httpHandlers>
  <add verb="GET" path="BarcodeHandler.aspx" type="Bokai.Barcodes.BarcodeHandler, Bokai.Barcodes" />
</httpHandlers>
Then you can use BarcodeHandler.aspx the same way you would the Barcode.aspx file, except that for BarcodeHandler.aspx, you don't need to specify any file path (actually, any file path would be fine, too), because BarcodeHandler.aspx is not an actual file but just a way for you to invoke the the HTTP handler BarcodeHandler.

USING THE BarcodeImage WEB SERVER CONTROL

BarcodeImage is a Web Server Control and can be used the same way you would the ASP.NET Image Web Server Control. It executes on the server side to generate the HTML <img src="..."> element with the src attribute pointing to either Barcode.aspx or BarcodeHandler.aspx. You might want to use BarcodeImage, instead of Barcode.aspx or BarcodeHandler.aspx directly, if you want to take advantage of the design time support of Visual Studio .Net.