locked
HttpHandler output : context.Response.BinaryWrite(..) or context.Response.OutputStream.Write(..) ? RRS feed

  • Question

  • User-484987990 posted

    Hi folks,

    i've made a simple handler that takes in a giud (asp.net membership guid) and then returns an avatar joined to the guid account.
    eg. < img src = "~/blah.img" ... / >

     Works, fine, etc.

    When it comes to the actual writing of the byte[] back to the client we have TWO options to use.

    a) context.Response.BinaryWrite(..)
    or
    b)  context.Response.OutputStream.Write(..)

    is it bad to use BinaryWrite to dump the image data back to the user? The reason i'm asking is that i would prefer NOT to store the content type of the uploaded avatar image ... but if i have to then i will if the outputstream method is better.

    Outputstream i think also requires the use of the Reponse.ContentType property getting set (eg. "image/png").

    thoughts?

    Sunday, January 7, 2007 2:38 AM

Answers

  • User-158764254 posted

    Response.BinaryWrite actually calls to  OutputStream.Write - so essentially they are the same...
    For either method, you should set the proper contenttype header.

    Here is what was viewed from Reflector as the source of Response.BinaryWrite:

    Public Sub BinaryWrite(ByVal buffer As Byte())
          Me.OutputStream.Write(buffer, 0, buffer.Length)
    End Sub
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 7, 2007 12:14 PM

All replies

  • User-158764254 posted

    Response.BinaryWrite actually calls to  OutputStream.Write - so essentially they are the same...
    For either method, you should set the proper contenttype header.

    Here is what was viewed from Reflector as the source of Response.BinaryWrite:

    Public Sub BinaryWrite(ByVal buffer As Byte())
          Me.OutputStream.Write(buffer, 0, buffer.Length)
    End Sub
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 7, 2007 12:14 PM
  • User-484987990 posted

    heh : ) that's what i'm already doing. doh :)

     cheers .. and i don't know why i didn't think of using reflector also ... *blush*

    Monday, January 8, 2007 10:10 PM