Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

IHttpAsyncHandler outputting ashx directive

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ghause - 24 Apr 2008 21:44 GMT
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 - 25 Apr 2008 14:41 GMT
> I'm trying to stream in image from another domain asynchronously.
> My ashx looks like this:
[quoted text clipped - 26 lines]
>
>             _webreq =

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

>             Return _webreq.BeginGetResponse(cb, extraData)
>         End Function
[quoted text clipped - 7 lines]
>
>                 Image =

getImageByteArray(System.Drawing.Image.FromStream(response.GetResponseStream
()))
>                 _context.Response.ContentType = "image/jpeg"
>                 _context.Response.AddHeader("Vary", "User-Agent")
[quoted text clipped - 29 lines]
>
> 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.

Signature

Anthony Jones - MVP ASP/ASP.NET


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.