ASHX IsReusable issue

T

timo

The calling page cannot get the image returned by this generic handler
unless its IsReusable property is set to True. If it is set to False,
the image never displays on the calling page:

Dim img As Web.UI.WebControls.Image
img = CType(Me.FindControl("myimage"), Web.UI.WebControls.Image)
img.ImageUrl = "GetImage.ashx?imagevalue=12345"



Will IsReusable=True cause problems on a busy website, where the image
changes based on dynamic conditions of the user session? The imagevalue
parameter changes all the time.

Thanks



Imports System.Web
Imports System.Web.Services

Public Class GetImage
Implements System.Web.IHttpHandler

Sub ProcessRequest(ByVal context As HttpContext) Implements
IHttpHandler.ProcessRequest


Dim myImageCreator As New ImageCreator
Dim imgvalue As UInt64
imgvalue = Int64.Parse(context.Request("imagevalue").ToString)

Dim imagestream As New System.IO.MemoryStream
myImageCreator.createGif(imagestream, imgvalue)


context.Response.Expires = 0
context.Response.Buffer = False
context.Response.Clear()
context.Response.ClearHeaders()
context.Response.ClearContent()
context.Response.ContentType = "image/gif"
context.Response.BinaryWrite(imagestream.ToArray)
context.Response.Flush()
context.Response.Close()


End Sub

ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable
Get
Return True
End Get
End Property

End Class
 
J

jacerhea

Will IsReusable=True cause problems on a busy website, where the image
changes based on dynamic conditions of the user session? The imagevalue
parameter changes all the time.

Yes, it seems that it will cause concurrency problems.
http://foreachbiscuit.wordpress.com/2007/11/01/isreusable-on-the-ihttphandler-interface/

I'm not sure why your code isn't working when isResusable is set to
false, it seems that only true would cause problems. I tried this
code and and it worked fine with isReuseable is false.

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

Imports System.Web
Imports System.Web.Services

Public Class GetImage : Implements IHttpHandler

Sub ProcessRequest(ByVal context As HttpContext) Implements
IHttpHandler.ProcessRequest

context.Response.Expires = 0
context.Response.Buffer = False
context.Response.Clear()
context.Response.ClearHeaders()
context.Response.ClearContent()
context.Response.ContentType = "image/gif"
context.Response.WriteFile("images\rover.gif") 'file from my
local web app
context.Response.Flush()
context.Response.Close()

End Sub

Public ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top