473,763 Members | 6,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IHttpAsyncHandl er outputting ashx directive

I'm trying to stream in image from another domain asynchronously.
My ashx looks like this:
<%@ WebHandler Language="VB" Class="Handlers .AsyncImageHand ler" Debug="true"
%>

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

Namespace .Handlers

Public Class AsyncImageHandl er
Implements System.Web.IHtt pAsyncHandler

Private _context As HttpContext
Private _webreq As HttpWebRequest

Sub ProcessRequest( ByVal context As HttpContext) _
Implements System.Web.IHtt pHandler.Proces sRequest
Throw New InvalidOperatio nException()
End Sub
Function BeginProcessReq uest(ByVal context As HttpContext, ByVal cb
As AsyncCallback, ByVal extraData As Object) As IAsyncResult _
Implements System.Web.IHtt pAsyncHandler.B eginProcessRequ est

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

_webreq =
DirectCast(WebR equest.Create(" http://www.nws.noaa.go v/weather/images/fcicons/shra20.jpg"), HttpWebRequest)

Return _webreq.BeginGe tResponse(cb, extraData)
End Function

Sub EndProcessReque st(ByVal result As IAsyncResult) _
Implements System.Web.IHtt pAsyncHandler.E ndProcessReques t
Try
Dim response As HttpWebResponse =
CType(_webreq.E ndGetResponse(r esult), HttpWebResponse )
Dim Image As Byte()

Image =
getImageByteArr ay(System.Drawi ng.Image.FromSt ream(response.G etResponseStrea m()))
_context.Respon se.ContentType = "image/jpeg"
_context.Respon se.AddHeader("V ary", "User-Agent")

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

End Try
End Sub

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

Private Function getImageByteArr ay(ByVal image As
System.Drawing. Image) As Byte()
Dim ms As New MemoryStream()
image.Save(ms, System.Drawing. Imaging.ImageFo rmat.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 .AsyncImageHand ler" Debug="true"
%>
����

What could I be doing that is sending the handler directive in the response?
Jun 27 '08 #1
1 2570
"ghause" <gh****@discuss ions.microsoft. comwrote in message
news:9B******** *************** ***********@mic rosoft.com...
I'm trying to stream in image from another domain asynchronously.
My ashx looks like this:
<%@ WebHandler Language="VB" Class="Handlers .AsyncImageHand ler"
Debug="true"
%>

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

Namespace .Handlers

Public Class AsyncImageHandl er
Implements System.Web.IHtt pAsyncHandler

Private _context As HttpContext
Private _webreq As HttpWebRequest

Sub ProcessRequest( ByVal context As HttpContext) _
Implements System.Web.IHtt pHandler.Proces sRequest
Throw New InvalidOperatio nException()
End Sub
Function BeginProcessReq uest(ByVal context As HttpContext, ByVal
cb
As AsyncCallback, ByVal extraData As Object) As IAsyncResult _
Implements System.Web.IHtt pAsyncHandler.B eginProcessRequ est

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

_webreq =
DirectCast(WebR equest.Create(" http://www.nws.noaa.go v/weather/images/fcicons
/shra20.jpg"), HttpWebRequest)
>
Return _webreq.BeginGe tResponse(cb, extraData)
End Function

Sub EndProcessReque st(ByVal result As IAsyncResult) _
Implements System.Web.IHtt pAsyncHandler.E ndProcessReques t
Try
Dim response As HttpWebResponse =
CType(_webreq.E ndGetResponse(r esult), HttpWebResponse )
Dim Image As Byte()

Image =
getImageByteArr ay(System.Drawi ng.Image.FromSt ream(response.G etResponseStrea m
()))
_context.Respon se.ContentType = "image/jpeg"
_context.Respon se.AddHeader("V ary", "User-Agent")

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

End Try
End Sub

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

Private Function getImageByteArr ay(ByVal image As
System.Drawing. Image) As Byte()
Dim ms As New MemoryStream()
image.Save(ms, System.Drawing. Imaging.ImageFo rmat.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 .AsyncImageHand ler"
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\Micr osoft.NET\Frame work\vXXXXX\asp net_isapi.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
3846
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 IHttpAsyncHandler object to the System and transfer the Request and Result between the two. This works fine for quite a while, and then I start to get the following error. "This remoting proxy has no channel sink which means either the server has
0
2711
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 Session or the Context cache. e.g. (in the aspx page) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Context.Current.Items.Add("Msg", "NAM2") Me.Session.Add("Msg", "NAM2")...
1
2150
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 famous Fritz Onion article on IHttpAsyncHandler...) I understand most of the code, however I am at a losss of the purpose of the ThreadInfo class. It appears that it is used to get the current HTTP context object for a worker thread?? But, can't...
5
7084
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 using aspx files because they don't have to be compiled and don't need any page processing. As an experiment, I'm creating an affiliate site that will use ashx files mainly. During testing I haven't noticed anything different other than it seems...
3
4087
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
6377
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 can I add *.ashx files to the publish target?
2
3348
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 EndProcessRequest never runs and the page hangs forever. Any idea why? Public Class MyAsyncWebHandler Implements IHttpAsyncHandler Implements IReadOnlySessionState
7
2832
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 seems to work fine, however I noticed that no web log entry is added when a successful download occurs (normally a 200 HTTP status code, however, if there is an authorization failure, it gets logged). I have a logging routine that logs a successful...
3
17693
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 begun. So here is JQuery call $.ajax({ type: 'POST', url: url,
0
10002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.