IHttpAsyncHandler outputting ashx directive

G

ghause

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?
 
A

Anthony Jones

ghause said:
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?

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.
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top