Your application stores images in a database that you want to display on a web form.
Create a web form that reads the image data from the database and streams the image to the
In the .aspx file, enter an @
Page directive and omit any head or body tags to link the .aspx page to the code-behind class that retrieves and displays the images:
Read the image ID that is generated by the running application—for example, the image ID passed in the URL for accessing the web form.
Open a connection to the database that contains the images.
Build a query string, and read the byte array of the desired image from the database.
Set the content type for the image and write it to the
To use this dynamic image generation technique in your application, set the
src attribute of the image tags used to display the images to the URL of the ASP.NET page that reads the images from the database, passing the image ID in the URL.
In the .aspx file for the page, add an
img tag for displaying the image.
In the code-behind class for the page that uses the image, use the .NET language of your choice to set the
src attribute of the image tag to the URL for the web form just described, passing the ID of the image in the URL.