BinaryWrite or OutputStream.Write

P

PrePort

The goal here is to return a dynamic image from an HttpHandler that I have
written. 2 questions

1. I am reading the images into byte[] fine and cacheing them fine, but what
should I use to deliver the image to the client?
My code:

context.Response.ContentType = "image/gif";
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
context.Response.Cache.SetExpires(DateTime.MinValue);
context.Response.BufferOutput = false;
context.Response.BinaryWrite(imageBytes);

or should the last line be:
context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length);

2. Should I do something like this:

context.Response.AddHeader("Content-Disposition","inline;filename=random.gif");
 
T

tdavisjr

I wouldn't add the Content-Disposition header as this may prompt the
user to save or open the image file. You already set the ContentType to
an image type.

As for BinaryWrite or OutputStream.Write, I prefer BinaryWrite as a
short hand method. Under the covers, BinaryWrite most likely calls
Response.OutputSteam.Write
 
P

preport

You were correct:

From Reflector:

public void BinaryWrite(byte[] buffer)
{
this.OutputStream.Write(buffer, 0, buffer.Length);
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top