Tech Off Thread

10 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

ASP.Net page returned as Content Type image/jpeg

Back to Forum: Tech Off
  • User profile image
    qwert231

    I have an .aspx page that looks like this:
    <%@ Page language="vb" Inherits="thumb" AutoEventWireup="false" CodeFile="thumb.aspx.vb" %>

    And the code behind looks like this:

    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
     Try

      ' --- all my rendering code ---

      ' send the image to the viewer
      SendImage(outImage)
     Catch ex As Exception
      Response.Write(ex.ToString.Replace(Chr(10),
    "<br>"))
     End Try
    End Sub 'Page_Load

    Public Sub SendImage(ByVal inImage As Bitmap)
     
    Try
      ' set the mime type
      Response.Clear()
      Response.ContentType =
    "image/Jpeg"

      ' send the image to the viewer
      inImage.Save(Response.OutputStream, ImageFormat.Jpeg)
     Catch ex As Exception
      Throw New ApplicationException(ex.ToString)
     End Try
    End Sub 'SendImage

    In .Net 1.1 I could put a page with an image tag like this:
    <img src='thumb.aspx...'>

    And get the image, rendered through the code in the .aspx page. Now it doesn't work... the resulting Content Type I get is not image/Jpeg, but text/html.

    Any thoughts?

  • User profile image
    qwert231

    You can see the broken, .Net 2.0 version here:
    http://www.centurycolor.com/securebeta/thumb.aspx?Order=666666&Roll=001&Frame=DSCF0241&BW=False

    and the working .Net 1.1 version here:
    http://www.centurycolor.com/secure/thumb.aspx?Order=666666&Roll=001&Frame=DSCF0241&BW=False

    The user/pass for both is:
    century
    color494

    (This is a demo account and has limited access.)

  • User profile image
    Maurits

    I'm not getting a content-type header at all:

    HTTP/1.x 200 OK
    Date: Wed, 31 May 2006 18:07:14 GMT
    Server: Microsoft-IIS/6.0
    X-Powered-By: ASP.NET
    X-AspNet-Version: 2.0.50727
    Cache-Control: private
    Content-Length: 0

    ... and what's worse, I'm not getting any content.

    EDIT:

    See the MSDN example for saving JPEGs to an HTTP Response

    Note: image/jpeg, not image/Jpeg
    Response.Clear is called after Response.ContentType is set

    Response.BufferOutput is set to True
    Response.Flush is called after bmp.Save(...)

    EDIT2: Any way you can set a breakpoint and attach a debugger?  That would allow you to see what code path is being taken, and verify that the variables have their expected values.

  • User profile image
    hackman_3vil​Guy

    I think the only problem is "image/Jpeg" instead of the correct "image/jpeg".
    _________
    Compilr the online compiler C#, VB.NET, C, Fortran
    http://thehackman.blogspot.com

  • User profile image
    Maurits

    It's working now, I see Smiley

  • User profile image
    qwert231

    Yes... thank you. I took the code out of the code-behind, and put it in the page as they did. Thanks again.

  • User profile image
    Sven Groot

    qwert231 wrote:
    Yes... thank you. I took the code out of the code-behind, and put it in the page as they did. Thanks again.

    Just as an FYI for the future: I prefer to use .ashx for something like this because it has less overhead than a .aspx page (an aspx page brings the entire web forms framework with it, which you're not using). To create a .ashx file in VS2005, use the "Generic Handler" template. Then return you image in the ProcessRequest method.

  • User profile image
    hackman_3vil​Guy

    That's interesting. I had never heard of .ashx before.
    _________
    Compilr the online compiler C#, VB.NET, C, Fortran
    http://thehackman.blogspot.com/">http://thehackman.blogspot.com

  • User profile image
    Sven Groot

    hackman_3vilGuy wrote:
    That's interesting. I had never heard of .ashx before.

    It's fairly obscure. They've existed since ASP.NET 1.0, but since Visual Studio didn't offer any support until VS2005, not many people know about them.

  • User profile image
    blowdart

    Sven Groot wrote:
    hackman_3vilGuy wrote:That's interesting. I had never heard of .ashx before.

    It's fairly obscure. They've existed since ASP.NET 1.0, but since Visual Studio didn't offer any support until VS2005, not many people know about them.


    Or you could embedd the resources in 2.0 and use WebResources to pull it out of the assembly, assuming it's nice and static


Conversation locked

This conversation has been locked by the site admins. No new comments can be made.