Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IHttpAsyncHandler outputting ashx directive

1 view
Skip to first unread message

ghause

unread,
Apr 24, 2008, 4:44:00 PM4/24/08
to
I'm trying to stream in image from another domain asynchronously.
My ashx looks like this:
<%@ WebHandler Language="VB" Class="Handlers.AsyncImageHandler" Debug="true"
%>

Here is the vb:
Imports System.net
imports system.io

Namespace .Handlers

Public Class AsyncImageHandler
Implements System.Web.IHttpAsyncHandler

Private _context As HttpContext
Private _webreq As HttpWebRequest

Sub ProcessRequest(ByVal context As HttpContext) _
Implements System.Web.IHttpHandler.ProcessRequest
Throw New InvalidOperationException()
End Sub


Function BeginProcessRequest(ByVal context As HttpContext, ByVal cb
As AsyncCallback, ByVal extraData As Object) As IAsyncResult _
Implements System.Web.IHttpAsyncHandler.BeginProcessRequest

' Save a reference to the HttpContext
_context = System.Web.HttpContext.Current

_webreq =
DirectCast(WebRequest.Create("http://www.nws.noaa.gov/weather/images/fcicons/shra20.jpg"), HttpWebRequest)

Return _webreq.BeginGetResponse(cb, extraData)
End Function

Sub EndProcessRequest(ByVal result As IAsyncResult) _
Implements System.Web.IHttpAsyncHandler.EndProcessRequest
Try
Dim response As HttpWebResponse =
CType(_webreq.EndGetResponse(result), HttpWebResponse)
Dim Image As Byte()

Image =
getImageByteArray(System.Drawing.Image.FromStream(response.GetResponseStream()))
_context.Response.ContentType = "image/jpeg"
_context.Response.AddHeader("Vary", "User-Agent")

_context.Response.OutputStream.Write(Image, 78, Image.Length
- 78)
Finally

End Try
End Sub

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

Private Function getImageByteArray(ByVal image As
System.Drawing.Image) As Byte()
Dim ms As New MemoryStream()
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Return ms.ToArray()
End Function
End Class
End Namespace


The baffiling response content (in text format) looks like this:

<%@ WebHandler Language="VB" Class="Handlers.AsyncImageHandler" Debug="true"
%>
����

What could I be doing that is sending the handler directive in the response?

Anthony Jones

unread,
Apr 25, 2008, 9:41:32 AM4/25/08
to
"ghause" <gha...@discussions.microsoft.com> wrote in message
news:9B63B7C2-1414-4FBD...@microsoft.com...
> ????

>
> What could I be doing that is sending the handler directive in the
response?

Sounds like ASP.NET isn't correctly registered for the application.

.ashx should mapped to
C:\WINDOWS\Microsoft.NET\Framework\vXXXXX\aspnet_isapi.dll

as a script engine.

Try running aspnet_regiis again.

--
Anthony Jones - MVP ASP/ASP.NET


0 new messages