In aspx i addded an image control
<asp:image runat="server" id="ImageViewer" imageurl="~/Handler1.ashx" xmlns:asp="#unknown" />
Then in code behind
Imports System.IO
Imports System.Drawing
Imports System.Data.SqlClient
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Con As New SqlConnection("data source=local;initial catalog=MYDB;User id=santhosh.kumar;password=pass@123")
Dim cmd As New SqlCommand("select cropImage from serverdocument where document_id=10217533", Con)
Dim data() As Byte
Con.Open()
data = cmd.ExecuteScalar()
Session("ImageBytes") = data
End Sub
End Class
Then i added new Generic handler.
Imports System.Web
Imports System.Web.Services
Public Class Handler1
Implements System.Web.IHttpHandler, System.Web.SessionState.IRequiresSessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
If (context.Session("ImageBytes")) IsNot Nothing Then
Dim image As Byte() = DirectCast(context.Session("ImageBytes"), Byte())
context.Response.ContentType = "image/JPEG"
context.Response.BinaryWrite(image)
End If
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Now run. It will display the image.