473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

IHttpAsyncHandler outputting ashx directive

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?
Jun 27 '08 #1
1 2552
"ghause" <gh****@discussions.microsoft.comwrote in message
news:9B**********************************@microsof t.com...
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_i sapi.dll

as a script engine.

Try running aspnet_regiis again.

--
Anthony Jones - MVP ASP/ASP.NET
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Grishaber | last post by:
Hello All, I am using an IHttpAsyncHandler class to intercept HTTP Requests and forward them to a system which processes the Request and returns the Result. I use .NET Remoting to connect the...
0
by: JJ | last post by:
I am trying to use .ashx files to handle dynamic image requests. The aspx page needs to pass the data to the ashx file. It was decided to not use the query string. Instead we hoped we could use the...
1
by: buzz | last post by:
I am evaluating Mike Woodring's custom thread pool classes (Developmentor) for use with an ASP.NET project that will be implementing pages derived from IHttpAsyncHandler. (Recommended by the...
5
by: Roshawn Dawson | last post by:
Hi, Has anybody created an entire asp.net app using only ashx files? I know that they are simply handlers used by the asp.net worker process. I hear that they are in some respects better than...
3
by: Tim | last post by:
Guys I am trying to create an ashx IHttpHandler that will provide images for me. This is what I have done so far. ' Start test.ashx <%@ WebHandler Language="VB" Class="testashx" %>
2
by: Max2006 | last post by:
Hi, After I right-click on my web application project file and choose "Publish ." and do the publishing, the result publishable files does not include the *.ashx files. Is it by design? How...
2
by: =?Utf-8?B?U3RldmUgV3JpZ2h0?= | last post by:
Hi All, This is my first time using this interface, so I am sure I am just missing something stupid. When my Http Handler gets called, the Begin runs and the delegate runs, but the...
7
by: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= | last post by:
Hi, I have been using the code (some of it has been removed for simplicity) below to allow authenticated (using ASP.NET membership database) users to get a file from their archive area. It...
3
by: George | last post by:
I am doing an AJAX call using JQuery on my page to which returns JSON objects and everything works fine. Now I decided to use ashx handler instead of and simply write JSON out. Then my problems...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.