<%@ WebHandler Language="VB" Class="ImageDisplayHandler" %>

Imports System
Imports System.Web
Imports System.Web.SessionState

Public Class ImageDisplayHandler : Implements IHttpHandler, IRequiresSessionState
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        If context.Session("DisplayImage") IsNot Nothing Then
            Dim obj = context.Session("DisplayImage")
            If TypeOf obj Is Byte() Then
                obj = DirectCast(context.Session("DisplayImage"), Byte())
                context.Response.ContentType = "image/gif"
                context.Response.AddHeader("Content-Length", obj.Length.ToString())
                context.Response.AddHeader("Content-Disposition", "inline")
                context.Response.BinaryWrite(obj)
                context.Session("DisplayImage") = Nothing
            End If
        End If
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class