Wrox Programmer Forums
|
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2006, 11:56 AM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapt 23 Cannot get HttpHandlers to work.


I am trying to create an HttpHandler as discussed in Chapt 23 pages 945 and 946.

I receive the following error:
Parser Error Message: Could not load file or assembly 'App_Code' or one of its dependencies. The system cannot find the file specified.

The only modification that may be causing me grief was from early in the book, Chapt 3 page 80, structuring the web.config file so that classes in the \App_Code folder can use different languages. However, the \App_Code\VB gives the same error.

After trying different type commands settings. I still could not get anything to work. Then I came accross the following post http://www.codecomments.com/archive2...10-672264.html. This posting says just to leave off the App_Code parameter, it is not required. Leaving off the parameter eliminated the error. However, now when I specify the URL in the browser, I get a "The page cannot be found" error in the browser.

Here is my browser address, the application's web config and program's class declarations:

Code:
http://localhost/WebApplication1/WebCam.img

Code:
<httpHandlers>
      <add verb ="*" path ="WebCam.img" type="MappedWebCamCapture"/>
    </httpHandlers>

Code:

Public Class MappedWebCamCapture : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "image/jpg"
....

Also, when using example on page 943, using *ashx files and outputting an image from an HttpHandler. This works great on the local server. However, when specifying the url remotely, the browser does not know how to handle the request. It first asks me if i want to download the ashx file. When I say yes, and specify to save as image.jpg, I can save and open the image. Additional, if I specify the url in an asp page on a remote server image control will the show the image.
Why won't the local computer serve up the remote image?

 
Old March 22nd, 2006, 06:35 PM
Wrox Author
 
Join Date: Dec 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It does look like when you are using the codeSubDirectories as described in Chapter 3, that specifying the App_Code portion of the type attribute causes the exception you described. I guess when I wrote that chapter I did not have that configuration set up in my web.config. That said, it does also look like removing the App_Code directory does allow the handler to work properly.

Basically the type attribute has two pieces of data in it, the object Type that ASP.NET needs to use when the request is made, and the location of that Type, which you can either specify as an assembly name (Foo.dll), or as App_Code. It looks like ASP.NET can also assume that the Type is in the calling assembly if no location is provided (in fact I think it looks locally first for perf reasons).

I noticed your browser address did not include a port number so I assume your using IIS as your web server, rather than the built-in Visual Studio development web server. I set up a project using IIS as the web server and also got a 404 when testing my handler, so I have a feeling that the problem is that IIS does not understand what the .img extension is. You might have to set up that extension in IIS so it know to process the request using ASP.NET.

As far as your second question, are you actually putting an HTTP address in the WriteFile() method? I am pretty sure that won't work, and that you would need to use the HttpRequest/Response methods within your Handler to reterive the image from the remote server, then pass it on to the requesting client.

Maybe I misunderstood that question...

Devin
 
Old March 22nd, 2006, 08:59 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am now able to display an image through a
browser on a remote site using the example on Page 943.

The devil is in the details...or stupid mistakes.

When I changed the context.Response.ContentType = "image/jpg"
to context.Response.ContentType = "image/Jpeg". As shown in the book and I am now able to display the image remotely through the browser. :D

Pasting the following link in my browser will display an image:
Code:
http://xp1.twelb.com/WebApplication1/WebCamCapture.ashx
However,
I am still not able to make a remote reference to a .ashx image through by specifying the ashx file as the url. I reference an .ashx file on localserver in either location an the image will show. However, when the .ashx file comes from a remote server the web page does not display the image.

The code below pulls in images from remote and local sources. The local images are displayed, the remote gifs are displayed, the remote .ashx images do not diplay. However, I can get the images to display when I paste the url in my browser.


Code:
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports System.Text
Public Class _default
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        ListFiles()
    End Sub
    Private Sub ListFiles()

        Dim sb As StringBuilder = New StringBuilder(4096)
        Dim imageUrl As String
        Dim displayUrl As String

        sb.Append("<DIV id='scroll1' style='border: 1px solid Gray; OVERFLOW: auto; WIDTH: 100%; HEIGHT: 500px;'>")
        sb.Append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>")
        sb.Append("<tr>")
        sb.Append("</td>")

        sb.Append("<td  width='8' height='20' ></td>")
        sb.Append("<td  align='right'>Size</td>")
        sb.Append("<td  width='8' height='20'></td>")

        sb.Append("<td  width='8' height='20' ></td>")
        sb.Append("</tr>")
        Try


            sb.Append("<tr>")

            imageUrl = "http://xp1.twelb.com/webApplication1/ThumbnailHandler.Ashx?ImgFilePath=images/ImagesalimaOFF.jpg&width=100&height=100"
            displayUrl = "http://xp1.twelb.com/webApplication1/ThumbnailHandler.Ashx?ImgFilePath=images/ImagesalimaOFF.jpg&width=100&height=100"
            sb.Append("<td>&nbsp;</td>")
            sb.Append("<td  valign='top'><img src='" + imageUrl + "'> ")
            sb.Append("<a target='_blank' href='" + displayUrl + "'>" + "Thumbnail" + "</a></td>")
            sb.Append("<td>&nbsp;</td>")
            sb.Append("</tr>")

            imageUrl = "http://xp1.twelb.com/WebApplication1/WebCamCapture.ashx"
            displayUrl = "http://xp1.twelb.com/WebApplication1/WebCamCapture.ashx"
            sb.Append("<td>&nbsp;</td>")
            sb.Append("<td  valign='top'><img src='" + imageUrl + "'> ")
            sb.Append("<a target='_blank' href='" + displayUrl + "'>" + "WebCam" + "</a></td>")
            sb.Append("<td>&nbsp;</td>")
            sb.Append("</tr>")

            imageUrl = "http://xp1.twelb.com/WebApplication1/0.gif"
            displayUrl = "http://xp1.twelb.com/WebApplication1/0.gif"

            sb.Append("<td>&nbsp;</td>")
            sb.Append("<td  valign='top'><img src='" + imageUrl + "'> ")
            sb.Append("<a target='_blank' href='" + displayUrl + "'>" + " remote fish" + "</a></td>")
            sb.Append("<td>&nbsp;</td>")
            sb.Append("</tr>")

            imageUrl = "http://localhost/Thumbgen/Thumbnail.Ashx?ImgFilePath=images/doc.jpg&width=100&height=100"
            displayUrl = "http://localhost/Thumbgen/Thumbnail.Ashx?ImgFilePath=images/doc.jpg&width=100&height=100"

            sb.Append("<td>&nbsp;</td>")
            sb.Append("<td  valign='top'><img src='" + imageUrl + "'> ")
            sb.Append("<a target='_blank' href='" + displayUrl + "'>" + "Doctor" + "</a></td>")
            sb.Append("<td>&nbsp;</td>")
            sb.Append("</tr>")

            imageUrl = "http://localhost/WebAppSmartHome/0.gif"
            displayUrl = "http://localhost/WebAppSmartHome/0.gif"
            sb.Append("<td>&nbsp;</td>")
            sb.Append("<td  valign='top'><img src='" + imageUrl + "'> ")
            sb.Append("<a target='_blank' href='" + displayUrl + "'>" + "local fish" + "</a></td>")
            sb.Append("<td>&nbsp;</td>")
            sb.Append("</tr>")
        Catch ex As Exception

            System.Diagnostics.Debug.WriteLine(ex.Message)
        End Try
        sb.Append("</table>")
        sb.Append("</div>")
        Response.Write(sb.ToString())
    End Sub
End Class
For now, I am focusing on .ashx types of file handlers and putting the class-based image HttpHandler on hold. I keep getting a url not found even after adding the file type to IIS.


Quote:
quote:Originally posted by dhacker@svtv.com


Code:

Public Class MappedWebCamCapture : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "image/jpg"
....





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems in Chapt 9 pjwarez BOOK: Beginning Mac OS X Programming 0 August 30th, 2006 02:46 PM
Chapt 5 Help needed with Form4 example Getting_there_slowly BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 May 28th, 2005 10:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.