Problem with asp page returning a jpg image...

Discussion in 'ASP General' started by Peter, Oct 4, 2006.

  1. Peter

    Peter Guest

    I have a problem with a page show_image.asp that returns a jpg image under
    Windows XP Pro SP2. The page sets content type as:

    Response.ContentType = "image/jpg"

    While this works perfectly fine on most machines, on some machines I
    experience this problem:

    When loading the page a window pops up that asks if I want to open the
    document show_page.asp. When I click "Open" Interdev pops up and opens up a
    window titled show_image.asp but the contents of that page has a few html
    tags at the top followed by the binary jpg data. In fact, if I delete the
    html tags and save the page as something.jpg and then look at it, it shows
    the expected image.

    I've noticed this problem before and found on some machines that disabling
    server side debugging for the virtual directory in IIS admin does the trick.
    On other occasions, I recreated the server extensions and that solved it. I
    have never completely managed to understand why this happens and a reliable
    way to fix it.

    Any ideas?
     
    Peter, Oct 4, 2006
    #1
    1. Advertising

  2. Peter

    Larry Bud Guest

    Peter wrote:
    > I have a problem with a page show_image.asp that returns a jpg image under
    > Windows XP Pro SP2. The page sets content type as:
    >
    > Response.ContentType = "image/jpg"
    >
    > While this works perfectly fine on most machines, on some machines I
    > experience this problem:
    >
    > When loading the page a window pops up that asks if I want to open the
    > document show_page.asp. When I click "Open" Interdev pops up and opens up a
    > window titled show_image.asp but the contents of that page has a few html
    > tags at the top followed by the binary jpg data.


    Why not show us "show_page.asp"??
     
    Larry Bud, Oct 10, 2006
    #2
    1. Advertising

  3. Peter

    Peter Guest

    OK, here it goes:

    test.asp
    --------
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html">
    <title>Test Warehouse layout</title>
    </head>
    <body>
    <img src="show_image.asp">
    </body>
    </html>


    show_image.asp:
    ---------------
    <%@ Language=VBScript %>
    <%
    Option Explicit

    Response.Expires = -1
    Response.Buffer = True
    Response.ContentType = "image/jpg"

    Dim objWarehouse

    Set objWarehouse = mlobjAPP3Database.Warehouse()

    If Not objWarehouse Is Nothing Then
    Response.BinaryWrite objWarehouse.LayoutJPG()
    End If
    %>

    Please don't forget that this works on most machines. However, I frequently
    have troubles on development machines and wonder if it has something to do
    with server/client side debugging being enabled for IIS or if it has
    something to do with frontpage or interdev IIS extensions.

    Pete

    "Larry Bud" <> wrote in message
    news:...
    >
    > Peter wrote:
    >> I have a problem with a page show_image.asp that returns a jpg image
    >> under
    >> Windows XP Pro SP2. The page sets content type as:
    >>
    >> Response.ContentType = "image/jpg"
    >>
    >> While this works perfectly fine on most machines, on some machines I
    >> experience this problem:
    >>
    >> When loading the page a window pops up that asks if I want to open the
    >> document show_image.asp. When I click "Open" Interdev pops up and opens
    >> up a
    >> window titled show_image.asp but the contents of that page has a few html
    >> tags at the top followed by the binary jpg data.

    >
    > Why not show us "show_image.asp"??
    >
     
    Peter, Oct 12, 2006
    #3
  4. Peter wrote:
    > Response.ContentType = "image/jpg"


    If you look at the content-type sent by the browser when you UPLOAD a jpg
    file, you will find that it is "image/jpeg", not "image/jpg". Furthermore,
    IIS 6 sends "image/jpeg" in the content-type header for .jpg requests. Try
    changing your code to a recognized content type.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Oct 12, 2006
    #4
  5. Peter

    Peter Guest

    Thanks heaps Dave, your reply was spot on and fix my problem!!!

    "Dave Anderson" <> wrote in message
    news:...
    > Peter wrote:
    >> Response.ContentType = "image/jpg"

    >
    > If you look at the content-type sent by the browser when you UPLOAD a jpg
    > file, you will find that it is "image/jpeg", not "image/jpg". Furthermore,
    > IIS 6 sends "image/jpeg" in the content-type header for .jpg requests. Try
    > changing your code to a recognized content type.
    >
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.
    > Use of this email address implies consent to these terms.
    >
     
    Peter, Oct 12, 2006
    #5
  6. Peter

    Peter Guest

    Now I have a similar problem again on another machine.

    In the message below I used Response.ContentType = "image/jpg" and after
    changing it to Response.ContentType = "image/jpeg" it alworked on the
    machine I had trouble back then.

    Now I have a similar problem once again even though I am now returning the
    correct mime type.

    The behaviour is as follows:

    IE 7.0:
    http://localhost/test.asp simply shows the icon for a missing image instead
    of the image
    http://localhost/show_image.asp shows some raw image data

    Mozilla Firefox 2.0:
    http://localhost/test.asp simply shows the icon for a missing image instead
    of the image
    http://localhost/show_image.asp shows the URL as text in the client area
    instead of the image

    I ammendet show_image.asp to also write the binary data to an physical file
    c:\temp\image.jpg. I can see that the image is updated each time i request
    either of the two URL's and this works fine. Furthermore, the image looks
    fine too.

    I really have no idea what is wrong with... Is this an incorrect approach???

    Pete


    "Peter" <peteATkapiti.co.nz> wrote in message
    news:...
    > OK, here it goes:
    >
    > test.asp
    > --------
    > <html>
    > <head>
    > <meta http-equiv="Content-Type" content="text/html">
    > <title>Test Warehouse layout</title>
    > </head>
    > <body>
    > <img src="show_image.asp">
    > </body>
    > </html>
    >
    >
    > show_image.asp:
    > ---------------
    > <%@ Language=VBScript %>
    > <%
    > Option Explicit
    >
    > Response.Expires = -1
    > Response.Buffer = True
    > Response.ContentType = "image/jpg"
    >
    > Dim objWarehouse
    >
    > Set objWarehouse = mlobjAPP3Database.Warehouse()
    >
    > If Not objWarehouse Is Nothing Then
    > Response.BinaryWrite objWarehouse.LayoutJPG()
    > End If
    > %>
    >
    > Please don't forget that this works on most machines. However, I
    > frequently have troubles on development machines and wonder if it has
    > something to do with server/client side debugging being enabled for IIS or
    > if it has something to do with frontpage or interdev IIS extensions.
    >
    > Pete
    >
    > "Larry Bud" <> wrote in message
    > news:...
    >>
    >> Peter wrote:
    >>> I have a problem with a page show_image.asp that returns a jpg image
    >>> under
    >>> Windows XP Pro SP2. The page sets content type as:
    >>>
    >>> Response.ContentType = "image/jpg"
    >>>
    >>> While this works perfectly fine on most machines, on some machines I
    >>> experience this problem:
    >>>
    >>> When loading the page a window pops up that asks if I want to open the
    >>> document show_image.asp. When I click "Open" Interdev pops up and opens
    >>> up a
    >>> window titled show_image.asp but the contents of that page has a few
    >>> html
    >>> tags at the top followed by the binary jpg data.

    >>
    >> Why not show us "show_image.asp"??
    >>

    >
    >
     
    Peter, Nov 16, 2006
    #6
  7. Peter wrote:
    > Now I have a similar problem again on another machine.
    >
    > In the message below I used Response.ContentType = "image/jpg" and
    > after changing it to Response.ContentType = "image/jpeg" it alworked
    > on the machine I had trouble back then.
    >
    > Now I have a similar problem once again even though I am now
    > returning the correct mime type.
    >
    > The behaviour is as follows:
    >
    > IE 7.0:
    > http://localhost/test.asp simply shows the icon for a missing image
    > instead of the image
    > http://localhost/show_image.asp shows some raw image data
    >
    > Mozilla Firefox 2.0:
    > http://localhost/test.asp simply shows the icon for a missing image
    > instead of the image
    > http://localhost/show_image.asp shows the URL as text in the client
    > area instead of the image


    I see several conditions here that are not accounted for:

    >>> Set objWarehouse = mlobjAPP3Database.Warehouse()
    >>> If Not objWarehouse Is Nothing Then
    >>> Response.BinaryWrite objWarehouse.LayoutJPG()
    >>> End If


    Since we know almost nothing about mlobjAPP3Database, it isn't clear that
    the choices are [Nothing] and [an object with nontrivial method
    LayoutJPG()]. Moreover, the method name suggests the image is always in the
    jpeg format. Are you certain this is the case?


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Nov 17, 2006
    #7
  8. Peter

    Peter Guest

    "Dave Anderson" <> wrote in message
    news:...
    > Peter wrote:
    >> Now I have a similar problem again on another machine.
    >>
    >> In the message below I used Response.ContentType = "image/jpg" and
    >> after changing it to Response.ContentType = "image/jpeg" it alworked
    >> on the machine I had trouble back then.
    >>
    >> Now I have a similar problem once again even though I am now
    >> returning the correct mime type.
    >>
    >> The behaviour is as follows:
    >>
    >> IE 7.0:
    >> http://localhost/test.asp simply shows the icon for a missing image
    >> instead of the image
    >> http://localhost/show_image.asp shows some raw image data
    >>
    >> Mozilla Firefox 2.0:
    >> http://localhost/test.asp simply shows the icon for a missing image
    >> instead of the image
    >> http://localhost/show_image.asp shows the URL as text in the client
    >> area instead of the image

    >
    > I see several conditions here that are not accounted for:
    >
    >>>> Set objWarehouse = mlobjAPP3Database.Warehouse()
    >>>> If Not objWarehouse Is Nothing Then
    >>>> Response.BinaryWrite objWarehouse.LayoutJPG()
    >>>> End If

    >
    > Since we know almost nothing about mlobjAPP3Database, it isn't clear that
    > the choices are [Nothing] and [an object with nontrivial method
    > LayoutJPG()]. Moreover, the method name suggests the image is always in
    > the jpeg format. Are you certain this is the case?


    I accept your concerns, but I have reduced to code to the protions which are
    relevant for this dicussion. The problem is not with my code, the problem is
    somewhere with the configuration of IIS.

    I have expanded show_image.asp with the following function:

    Function SaveBinaryData(FileName, ByteArray)
    Const adTypeBinary = 1
    Const adSaveCreateOverWrite = 2

    'Create Stream object
    Dim BinaryStream
    Set BinaryStream = CreateObject("ADODB.Stream")

    'Specify stream type - we want To save binary data.
    BinaryStream.Type = adTypeBinary

    'Open the stream And write binary data To the object
    BinaryStream.Open
    BinaryStream.Write ByteArray

    'Save binary data To disk
    BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
    End Function

    Now not only do I write the raw data back to the client, I also write it to
    a physical file:

    Response.BinaryWrite objWarehouse.LayoutJPG()
    SaveBinaryData "c:\temp\mypic.jpg", objWarehouse.LayoutJPG()

    Not only can I see that c:\temp\mypic.jpg get's written correctly everytime
    I request the page from the web server, my web browsers and image viewers
    show the expected image when I open the file explicitly.

    There must be something wrong with IIS, I suspect it has something to do
    with front page server extensions or extensions needed for MS InterDev.

    Pete
     
    Peter, Nov 19, 2006
    #8
  9. Peter

    Peter Guest

    "Peter" <peteATkapiti.co.nz> wrote in message
    news:...
    > "Dave Anderson" <> wrote in message
    > news:...
    >> Peter wrote:
    >>> Now I have a similar problem again on another machine.
    >>>
    >>> In the message below I used Response.ContentType = "image/jpg" and
    >>> after changing it to Response.ContentType = "image/jpeg" it alworked
    >>> on the machine I had trouble back then.
    >>>
    >>> Now I have a similar problem once again even though I am now
    >>> returning the correct mime type.
    >>>
    >>> The behaviour is as follows:
    >>>
    >>> IE 7.0:
    >>> http://localhost/test.asp simply shows the icon for a missing image
    >>> instead of the image
    >>> http://localhost/show_image.asp shows some raw image data
    >>>
    >>> Mozilla Firefox 2.0:
    >>> http://localhost/test.asp simply shows the icon for a missing image
    >>> instead of the image
    >>> http://localhost/show_image.asp shows the URL as text in the client
    >>> area instead of the image

    >>
    >> I see several conditions here that are not accounted for:
    >>
    >>>>> Set objWarehouse = mlobjAPP3Database.Warehouse()
    >>>>> If Not objWarehouse Is Nothing Then
    >>>>> Response.BinaryWrite objWarehouse.LayoutJPG()
    >>>>> End If

    >>
    >> Since we know almost nothing about mlobjAPP3Database, it isn't clear that
    >> the choices are [Nothing] and [an object with nontrivial method
    >> LayoutJPG()]. Moreover, the method name suggests the image is always in
    >> the jpeg format. Are you certain this is the case?

    >
    > I accept your concerns, but I have reduced to code to the protions which
    > are relevant for this dicussion. The problem is not with my code, the
    > problem is somewhere with the configuration of IIS.
    >
    > I have expanded show_image.asp with the following function:
    >
    > Function SaveBinaryData(FileName, ByteArray)
    > Const adTypeBinary = 1
    > Const adSaveCreateOverWrite = 2
    >
    > 'Create Stream object
    > Dim BinaryStream
    > Set BinaryStream = CreateObject("ADODB.Stream")
    >
    > 'Specify stream type - we want To save binary data.
    > BinaryStream.Type = adTypeBinary
    >
    > 'Open the stream And write binary data To the object
    > BinaryStream.Open
    > BinaryStream.Write ByteArray
    >
    > 'Save binary data To disk
    > BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
    > End Function
    >
    > Now not only do I write the raw data back to the client, I also write it
    > to a physical file:
    >
    > Response.BinaryWrite objWarehouse.LayoutJPG()
    > SaveBinaryData "c:\temp\mypic.jpg", objWarehouse.LayoutJPG()
    >
    > Not only can I see that c:\temp\mypic.jpg get's written correctly
    > everytime I request the page from the web server, my web browsers and
    > image viewers show the expected image when I open the file explicitly.
    >
    > There must be something wrong with IIS, I suspect it has something to do
    > with front page server extensions or extensions needed for MS InterDev.


    Surprise, surprise...

    I now find that if I change show_image.asp as follows all works fine (note
    that all I changed was inserting a Response.Clear before and Response.Flush
    after writing the binary data to the output stream). Why would that be?

    <%@ Language=VBScript %>
    <%
    Option Explicit

    Response.Expires = -1
    Response.Buffer = True

    Dim objWarehouse

    Set objWarehouse = mlobjAPP3Database.Warehouse()

    If Not objWarehouse Is Nothing Then
    Response.Clear
    Response.ContentType = "image/jpeg"
    Response.BinaryWrite objWarehouse.LayoutJPG()
    Response.Flush
    End If
    %>
     
    Peter, Nov 19, 2006
    #9
  10. "Peter" <peteATkapiti.co.nz> wrote in message
    news:...
    >
    > "Peter" <peteATkapiti.co.nz> wrote in message
    > news:...
    > > "Dave Anderson" <> wrote in message
    > > news:...
    > >> Peter wrote:
    > >>> Now I have a similar problem again on another machine.
    > >>>
    > >>> In the message below I used Response.ContentType = "image/jpg" and
    > >>> after changing it to Response.ContentType = "image/jpeg" it alworked
    > >>> on the machine I had trouble back then.
    > >>>
    > >>> Now I have a similar problem once again even though I am now
    > >>> returning the correct mime type.
    > >>>
    > >>> The behaviour is as follows:
    > >>>
    > >>> IE 7.0:
    > >>> http://localhost/test.asp simply shows the icon for a missing image
    > >>> instead of the image
    > >>> http://localhost/show_image.asp shows some raw image data
    > >>>
    > >>> Mozilla Firefox 2.0:
    > >>> http://localhost/test.asp simply shows the icon for a missing image
    > >>> instead of the image
    > >>> http://localhost/show_image.asp shows the URL as text in the client
    > >>> area instead of the image
    > >>
    > >> I see several conditions here that are not accounted for:
    > >>
    > >>>>> Set objWarehouse = mlobjAPP3Database.Warehouse()
    > >>>>> If Not objWarehouse Is Nothing Then
    > >>>>> Response.BinaryWrite objWarehouse.LayoutJPG()
    > >>>>> End If
    > >>
    > >> Since we know almost nothing about mlobjAPP3Database, it isn't clear

    that
    > >> the choices are [Nothing] and [an object with nontrivial method
    > >> LayoutJPG()]. Moreover, the method name suggests the image is always in
    > >> the jpeg format. Are you certain this is the case?

    > >
    > > I accept your concerns, but I have reduced to code to the protions which
    > > are relevant for this dicussion. The problem is not with my code, the
    > > problem is somewhere with the configuration of IIS.
    > >
    > > I have expanded show_image.asp with the following function:
    > >
    > > Function SaveBinaryData(FileName, ByteArray)
    > > Const adTypeBinary = 1
    > > Const adSaveCreateOverWrite = 2
    > >
    > > 'Create Stream object
    > > Dim BinaryStream
    > > Set BinaryStream = CreateObject("ADODB.Stream")
    > >
    > > 'Specify stream type - we want To save binary data.
    > > BinaryStream.Type = adTypeBinary
    > >
    > > 'Open the stream And write binary data To the object
    > > BinaryStream.Open
    > > BinaryStream.Write ByteArray
    > >
    > > 'Save binary data To disk
    > > BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
    > > End Function
    > >
    > > Now not only do I write the raw data back to the client, I also write it
    > > to a physical file:
    > >
    > > Response.BinaryWrite objWarehouse.LayoutJPG()
    > > SaveBinaryData "c:\temp\mypic.jpg", objWarehouse.LayoutJPG()
    > >
    > > Not only can I see that c:\temp\mypic.jpg get's written correctly
    > > everytime I request the page from the web server, my web browsers and
    > > image viewers show the expected image when I open the file explicitly.
    > >
    > > There must be something wrong with IIS, I suspect it has something to do
    > > with front page server extensions or extensions needed for MS InterDev.

    >
    > Surprise, surprise...
    >
    > I now find that if I change show_image.asp as follows all works fine (note
    > that all I changed was inserting a Response.Clear before and

    Response.Flush
    > after writing the binary data to the output stream). Why would that be?
    >
    > <%@ Language=VBScript %>
    > <%
    > Option Explicit
    >
    > Response.Expires = -1
    > Response.Buffer = True
    >
    > Dim objWarehouse
    >
    > Set objWarehouse = mlobjAPP3Database.Warehouse()
    >
    > If Not objWarehouse Is Nothing Then
    > Response.Clear
    > Response.ContentType = "image/jpeg"
    > Response.BinaryWrite objWarehouse.LayoutJPG()
    > Response.Flush
    > End If
    > %>


    Sounds like there is some code running before this that was generating some
    output in the buffer.
    does the page have an include file that might be doing this?
    Is the page arrived at via Server.Transfer or Server.Execute?

    If you remove the .Flush does the problem come back?
     
    Anthony Jones, Nov 20, 2006
    #10
  11. Anthony Jones wrote:
    > Sounds like there is some code running before this that
    > was generating some output in the buffer.
    > does the page have an include file that might be doing
    > this? Is the page arrived at via Server.Transfer or
    > Server.Execute?


    This was my first question, but the example he provided had no other output.
    Once he explained that he had stripped out the chaff, it became clear there
    was probably more content in the Response buffer.

    This, by the way, is why I complete all processing before letting a script
    produce output. I do not even allow context switching until all connections
    are closed and decisions are made[1].




    [1] There is no point in putting something in the buffer if I'm going to use
    Response.Redirect, for example. A small amount of looping and conditional
    display is acceptible in the template, of course.

    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Nov 20, 2006
    #11
  12. Peter

    Peter Guest

    "Anthony Jones" <> wrote in message
    news:...
    >
    > "Peter" <peteATkapiti.co.nz> wrote in message
    > news:...
    >>
    >> "Peter" <peteATkapiti.co.nz> wrote in message
    >> news:...
    >> > "Dave Anderson" <> wrote in message
    >> > news:...
    >> >> Peter wrote:
    >> >>> Now I have a similar problem again on another machine.
    >> >>>
    >> >>> In the message below I used Response.ContentType = "image/jpg" and
    >> >>> after changing it to Response.ContentType = "image/jpeg" it alworked
    >> >>> on the machine I had trouble back then.
    >> >>>
    >> >>> Now I have a similar problem once again even though I am now
    >> >>> returning the correct mime type.
    >> >>>
    >> >>> The behaviour is as follows:
    >> >>>
    >> >>> IE 7.0:
    >> >>> http://localhost/test.asp simply shows the icon for a missing image
    >> >>> instead of the image
    >> >>> http://localhost/show_image.asp shows some raw image data
    >> >>>
    >> >>> Mozilla Firefox 2.0:
    >> >>> http://localhost/test.asp simply shows the icon for a missing image
    >> >>> instead of the image
    >> >>> http://localhost/show_image.asp shows the URL as text in the client
    >> >>> area instead of the image
    >> >>
    >> >> I see several conditions here that are not accounted for:
    >> >>
    >> >>>>> Set objWarehouse = mlobjAPP3Database.Warehouse()
    >> >>>>> If Not objWarehouse Is Nothing Then
    >> >>>>> Response.BinaryWrite objWarehouse.LayoutJPG()
    >> >>>>> End If
    >> >>
    >> >> Since we know almost nothing about mlobjAPP3Database, it isn't clear

    > that
    >> >> the choices are [Nothing] and [an object with nontrivial method
    >> >> LayoutJPG()]. Moreover, the method name suggests the image is always
    >> >> in
    >> >> the jpeg format. Are you certain this is the case?
    >> >
    >> > I accept your concerns, but I have reduced to code to the protions
    >> > which
    >> > are relevant for this dicussion. The problem is not with my code, the
    >> > problem is somewhere with the configuration of IIS.
    >> >
    >> > I have expanded show_image.asp with the following function:
    >> >
    >> > Function SaveBinaryData(FileName, ByteArray)
    >> > Const adTypeBinary = 1
    >> > Const adSaveCreateOverWrite = 2
    >> >
    >> > 'Create Stream object
    >> > Dim BinaryStream
    >> > Set BinaryStream = CreateObject("ADODB.Stream")
    >> >
    >> > 'Specify stream type - we want To save binary data.
    >> > BinaryStream.Type = adTypeBinary
    >> >
    >> > 'Open the stream And write binary data To the object
    >> > BinaryStream.Open
    >> > BinaryStream.Write ByteArray
    >> >
    >> > 'Save binary data To disk
    >> > BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
    >> > End Function
    >> >
    >> > Now not only do I write the raw data back to the client, I also write
    >> > it
    >> > to a physical file:
    >> >
    >> > Response.BinaryWrite objWarehouse.LayoutJPG()
    >> > SaveBinaryData "c:\temp\mypic.jpg", objWarehouse.LayoutJPG()
    >> >
    >> > Not only can I see that c:\temp\mypic.jpg get's written correctly
    >> > everytime I request the page from the web server, my web browsers and
    >> > image viewers show the expected image when I open the file explicitly.
    >> >
    >> > There must be something wrong with IIS, I suspect it has something to
    >> > do
    >> > with front page server extensions or extensions needed for MS InterDev.

    >>
    >> Surprise, surprise...
    >>
    >> I now find that if I change show_image.asp as follows all works fine
    >> (note
    >> that all I changed was inserting a Response.Clear before and

    > Response.Flush
    >> after writing the binary data to the output stream). Why would that be?
    >>
    >> <%@ Language=VBScript %>
    >> <%
    >> Option Explicit
    >>
    >> Response.Expires = -1
    >> Response.Buffer = True
    >>
    >> Dim objWarehouse
    >>
    >> Set objWarehouse = mlobjAPP3Database.Warehouse()
    >>
    >> If Not objWarehouse Is Nothing Then
    >> Response.Clear
    >> Response.ContentType = "image/jpeg"
    >> Response.BinaryWrite objWarehouse.LayoutJPG()
    >> Response.Flush
    >> End If
    >> %>

    >
    > Sounds like there is some code running before this that was generating
    > some
    > output in the buffer.
    > does the page have an include file that might be doing this?
    > Is the page arrived at via Server.Transfer or Server.Execute?
    >
    > If you remove the .Flush does the problem come back?


    This is plain old ASP (btw I'm a C++ programmer not ASP programmer and I
    wrote the component producing the image), so I don't know what
    Server.Execute or Server.Transfer is. The page is referenced by using the
    image tag in a calling page:

    <img src="show_image.asp">

    but you could equally well load the page directly.

    It is true that I do include another asp file in the real McCoy but the only
    time the include writes to the Response stream is to write an error message
    which is immediately followed by a Response.End call.

    I can remove the Flush and it still works perfectly fine, but if I remove
    the Clear it fails on that particular machine but works perfectly fine on
    many others.

    I hate the whole approach because it has a few flaws even if it works.
    Another thing I omitted is that show_image.asp actually takes some
    parameters (query string) like objectID, imgwidth, imgheight and rotation.
    Not all objects have images so I tried IFRAME instead of IMG and this works
    already a lot better since the page I'm loading can return any of the
    recognised content types and the browser can render it correctly. In other
    words, since I can return a jpg image, plain text, html, etc. I can return
    an error message if something goes wrong or the image if all works fine. But
    this approach too has it's flaws and feels like killing a fly with a cannon.

    Isn't there a better way to accomplish this?
     
    Peter, Nov 20, 2006
    #12
  13. "Peter" <peteATkapiti.co.nz> wrote in message
    news:...
    >
    > > If you remove the .Flush does the problem come back?

    >
    > This is plain old ASP (btw I'm a C++ programmer not ASP programmer and I
    > wrote the component producing the image), so I don't know what
    > Server.Execute or Server.Transfer is. The page is referenced by using the
    > image tag in a calling page:


    As a C++ programmer have you considered using an ISAPI filter or extension
    to acheive your goal.

    >
    > <img src="show_image.asp">
    >
    > but you could equally well load the page directly.


    Yes but instead of a html page you would be loading an image which browsers
    are quite happy to do.

    >
    > It is true that I do include another asp file in the real McCoy but the

    only
    > time the include writes to the Response stream is to write an error

    message
    > which is immediately followed by a Response.End call.


    Does it have any html mark up outside to the <%%> script delimiters. At the
    end of the day _something_ is adding this extra html markup into your output
    buffer. Does the application/parent application/site/server have any
    unusual ISAPI filters loaded?

    >
    > I can remove the Flush and it still works perfectly fine


    Then leave it out. There are very few genuine uses for Flush if any.

    > but if I remove
    > the Clear it fails on that particular machine but works perfectly fine on
    > many others.


    That's real strange. It would suggest that some machines are perfectly
    happy to swallow the preceeding html markup and ignore it.

    Does your ASP page set Expires or CacheControl properties of the Response
    object?
    Is it possible that the failing machine is actually retrieving an earlier
    corrupt resource from it's cache?

    >
    > I hate the whole approach because it has a few flaws even if it works.


    Such as?

    > Another thing I omitted is that show_image.asp actually takes some
    > parameters (query string) like objectID, imgwidth, imgheight and rotation.


    Not a problem

    > Not all objects have images so I tried IFRAME instead of IMG and this

    works
    > already a lot better since the page I'm loading can return any of the
    > recognised content types and the browser can render it correctly. In other
    > words, since I can return a jpg image, plain text, html, etc. I can return
    > an error message if something goes wrong or the image if all works fine.

    But
    > this approach too has it's flaws and feels like killing a fly with a

    cannon.
    >
    > Isn't there a better way to accomplish this?
    >


    If you're up for it then an ISAPI extension is a better solution. However
    the complexity may outweigh the benefits.

    Would it be true to say that ven the exact same set of query string values
    the page would return the exact same image. If so then consider using

    Response.Expires = <large number of minutes>
    Response.CacheControl = "max-age=" & <large number of minutes> * 60
    Response.AddHeader "ETag", "imageasp" & <some uniqueID for this exact image>

    This will cause the client to cache this image. Subsequent rquests for this
    image will be fulfilled from the cache.
     
    Anthony Jones, Nov 21, 2006
    #13
  14. Anthony Jones wrote:
    > Does it have any html mark up outside to the <%%> script
    > delimiters.


    More to the point, is there anything AT ALL (even whitespace) outside the
    script delimiters?




    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Nov 21, 2006
    #14
  15. Peter

    Peter Guest

    "Anthony Jones" <> wrote in message
    news:...
    >
    > "Peter" <peteATkapiti.co.nz> wrote in message
    > news:...
    >>
    >> > If you remove the .Flush does the problem come back?

    >>
    >> This is plain old ASP (btw I'm a C++ programmer not ASP programmer and I
    >> wrote the component producing the image), so I don't know what
    >> Server.Execute or Server.Transfer is. The page is referenced by using the
    >> image tag in a calling page:

    >
    > As a C++ programmer have you considered using an ISAPI filter or extension
    > to acheive your goal.


    A long time ago we did but at the time we decided against it because we felt
    that implementing a robust COM interface was a challenge enough.

    >> It is true that I do include another asp file in the real McCoy but the

    > only
    >> time the include writes to the Response stream is to write an error

    > message
    >> which is immediately followed by a Response.End call.

    >
    > Does it have any html mark up outside to the <%%> script delimiters. At
    > the
    > end of the day _something_ is adding this extra html markup into your
    > output
    > buffer. Does the application/parent application/site/server have any
    > unusual ISAPI filters loaded?


    I may have something like that:

    ' script finishes before this line
    %>

    <!--#Include File="_lib/pagestart.asp"-->

    <%
    ' more scripts follow

    Now would this write whitespace to the response stream?

    > Does your ASP page set Expires or CacheControl properties of the Response
    > object?


    This is all I do currently:

    Response.Expires = -1
    Response.Buffer = True


    > Is it possible that the failing machine is actually retrieving an earlier
    > corrupt resource from it's cache?


    I was hoping setting Response.Expires = -1 would cause a reload each
    time!?!?

    >> I hate the whole approach because it has a few flaws even if it works.

    >
    > Such as?


    What I hate is that my asp page that returns the image can't always return
    an image. Sometimes I can return text/plain or text/html instead of
    image/jpeg. But when I use the page as src attribute in an img tag it must
    return an image/* document so I can't easily return error messages.

    > If you're up for it then an ISAPI extension is a better solution. However
    > the complexity may outweigh the benefits.


    I think there is no justification at present since I know have it working
    better as is. Also, at present I don't have any machine that fails
    displaying graphics.

    > Would it be true to say that ven the exact same set of query string values
    > the page would return the exact same image. If so then consider using


    Unfortunately no. The COM server is rather a complex beast and has loads of
    runtime configurable parameters. Many of those can impact the 2D diagrams it
    produces.

    I really appreciate your feedback on this BTW! Many thanks Anthony and Dave!
     
    Peter, Nov 22, 2006
    #15
  16. "Peter" <peteATkapiti.co.nz> wrote in message
    news:%23$...
    > "Anthony Jones" <> wrote in message
    > news:...
    > >
    > > "Peter" <peteATkapiti.co.nz> wrote in message
    > > news:...
    > >>
    > >> > If you remove the .Flush does the problem come back?
    > >>
    > >> This is plain old ASP (btw I'm a C++ programmer not ASP programmer and

    I
    > >> wrote the component producing the image), so I don't know what
    > >> Server.Execute or Server.Transfer is. The page is referenced by using

    the
    > >> image tag in a calling page:

    > >
    > > As a C++ programmer have you considered using an ISAPI filter or

    extension
    > > to acheive your goal.

    >
    > A long time ago we did but at the time we decided against it because we

    felt
    > that implementing a robust COM interface was a challenge enough.
    >


    I hear ya! ;) One approach I've used is to create the a standard dll with
    C++ using StdCall exported functions. Create a typelib for those functions.
    Then build a VB6 ActiveX dll project that references the typelib and exposes
    a Script compatible set of COM objects. That way you let VB6 handle
    creating COM interfaces and stick to what you know in C++ (which in my case
    isn't a great deal).

    > >> It is true that I do include another asp file in the real McCoy but the

    > > only
    > >> time the include writes to the Response stream is to write an error

    > > message
    > >> which is immediately followed by a Response.End call.

    > >
    > > Does it have any html mark up outside to the <%%> script delimiters. At
    > > the
    > > end of the day _something_ is adding this extra html markup into your
    > > output
    > > buffer. Does the application/parent application/site/server have any
    > > unusual ISAPI filters loaded?

    >
    > I may have something like that:
    >
    > ' script finishes before this line
    > %>
    >
    > <!--#Include File="_lib/pagestart.asp"-->
    >
    > <%
    > ' more scripts follow
    >
    > Now would this write whitespace to the response stream?


    Like Dave said, this is very likely the culprit, it will at least be placing
    a couple or three CR LFs in the output.

    >
    > > Does your ASP page set Expires or CacheControl properties of the

    Response
    > > object?

    >
    > This is all I do currently:
    >
    > Response.Expires = -1
    > Response.Buffer = True
    >
    >
    > > Is it possible that the failing machine is actually retrieving an

    earlier
    > > corrupt resource from it's cache?

    >
    > I was hoping setting Response.Expires = -1 would cause a reload each
    > time!?!?
    >


    Yes should be. Although it does require that the client clock be in
    reasonable sync with the server clock. E.g. if the clients clock is 5
    minutes slow then Response.Expires=-1 allows the resource to remain fresh
    for 4 minutes.

    I tend to use Response.Expires = 0 and trust the clocks are reasonably in
    sync. However I also use:
    Response.CacheControl = "max-age=0" which is the HTTP/1.1 method of
    specifying freshness in seconds.


    > >> I hate the whole approach because it has a few flaws even if it works.

    > >
    > > Such as?

    >
    > What I hate is that my asp page that returns the image can't always return
    > an image. Sometimes I can return text/plain or text/html instead of
    > image/jpeg. But when I use the page as src attribute in an img tag it must
    > return an image/* document so I can't easily return error messages.
    >


    In that case you might consider inventing an 'Error.gif' which you can send
    in place of the image when an error occurs.

    > > If you're up for it then an ISAPI extension is a better solution.

    However
    > > the complexity may outweigh the benefits.

    >
    > I think there is no justification at present since I know have it working
    > better as is. Also, at present I don't have any machine that fails
    > displaying graphics.
    >
    > > Would it be true to say that ven the exact same set of query string

    values
    > > the page would return the exact same image. If so then consider using

    >
    > Unfortunately no. The COM server is rather a complex beast and has loads

    of
    > runtime configurable parameters. Many of those can impact the 2D diagrams

    it
    > produces.
    >


    In that case it does sound like you will need to ensure the resource is
    checked every time.

    > I really appreciate your feedback on this BTW! Many thanks Anthony and

    Dave!
    >
    >
    >
     
    Anthony Jones, Nov 22, 2006
    #16
  17. Peter

    Peter Guest

    To summarise what I will do as a result of this thread:

    1) The first statement I try to call will be Response.Buffer = True to
    ensure that nothing is sent to the client

    2) To ensure readability of code (blank lines in the right place assist me
    when I read code I wrote yonx ago) I will continue to use the Response.Clear
    command before outputing the image via Response.BinaryWrite

    3) In order to retain the ability to return informative text messages when
    no image is available or errors when creating the image fails for whatever
    reason, I'll embed the image in an iframe tag instead of an img tag.

    Thanks for all your help and suggestions Dave and Anthony! I think I have
    enough clues now to tidy this all up. I guess what was really confusing (and
    still is) was the fact that the same code worked on some machines but not on
    others. But then again, I don't understand much about the inner workings of
    different releases/configurations of IIS and now that I have a fix I don't
    really care to find out.

    I wish I had had guys like you on my team ;).

    Pete
     
    Peter, Nov 22, 2006
    #17

  18. > Instead of this...
    >
    > Some statement
    > %>
    >
    > <!-- #include file="abcdefg.inc.asp" -->
    >
    > <%
    > Some other statement
    >
    >
    > ...you simply change it to this:
    >
    >
    > Some statement
    >
    >
    > %><!-- #include file="abcdefg.inc.asp" --><%
    >
    >
    > Some other statement
    >
    >
    > That's no less readable, right?
    >


    Or

    %>
    <!-- #include file="abcdefg.inc.asp" -->
    <%

    ;)
     
    Anthony Jones, Nov 23, 2006
    #18
  19. Anthony Jones wrote:
    > Or
    >
    > %>
    > <!-- #include file="abcdefg.inc.asp" -->
    > <%


    No.

    You should pay attention to the thread before posting something like this.
    You just injected whitespace into the Response buffer, which now requires
    the use of Response.Clear() before using Response.BinaryWrite().



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Nov 24, 2006
    #19
  20. "Dave Anderson" <> wrote in message
    news:eI%...
    > Anthony Jones wrote:
    > > Or
    > >
    > > %>
    > > <!-- #include file="abcdefg.inc.asp" -->
    > > <%

    >
    > No.
    >
    > You should pay attention to the thread before posting something like this.
    > You just injected whitespace into the Response buffer, which now requires
    > the use of Response.Clear() before using Response.BinaryWrite().
    >


    I had a feeling you were going to say that. ;)

    Perhaps you should test your assumptions before handing out reproof.

    See my answer in this group to John Byrne subject 'IE7 XMLHTTPREQUEST
    reponseXML' orignal post sent 23-Nov-2006 14:05 GMT



    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.

    Use
    > of this email address implies consent to these terms.
    >
    >
     
    Anthony Jones, Nov 24, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roland
    Replies:
    0
    Views:
    1,096
    Roland
    May 12, 2004
  2. Matthias
    Replies:
    5
    Views:
    463
    Whitecrest
    Jun 1, 2004
  3. Yannick

    ASP changes Big JPG -> Small JPG

    Yannick, Feb 2, 2004, in forum: ASP General
    Replies:
    6
    Views:
    171
    Tim Williams
    Feb 3, 2004
  4. Vilmar Brazão de Oliveira
    Replies:
    14
    Views:
    379
    Aaron Bertrand [MVP]
    Mar 5, 2004
  5. Replies:
    3
    Views:
    280
    Andy Dingley
    Sep 27, 2006
Loading...

Share This Page