For some strange reason, a five year old internal asp.net web app that is used through IE6 has suddenly developed an issue, even though there have been no code changes. Certain images that are being streamed back to the web browser aren't appearing for some users.
I don't know why this was suddenly started happening or what the cause is - however as part of the search, I'm considering if there's a flaw in the code used to stream back images.
The image is held in memory are a byte array, then streamed back using the following code. Is this the best way to stream an image back?
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
// Work out file type
switch( Path.GetExtension( imageFilename ).ToLower() )
{
case ".jpg":
case ".jpeg":
Response.ContentType = "image/jpeg";
break;
case ".gif":
Response.ContentType = "image/gif";
break;
default:
Response.ContentType = "binary/octet-stream";
break;
}
Response.AddHeader("Content-Length", imageBytes.Length.ToString() );
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite( imageBytes );
Response.End();
Instead of an image being shown in the page, a red cross is displayed. This only happens with the dynamically generated images shown on the page, rather than the statically linked images.
If I try and open the image in it's own window, I either see the image or a load of gobbledygook text (Which I'm guessing means the MIME type isn't being set/picked up by the browser)