Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple image handler calls causing IE to hang in pop-up window

We have an ashx image handler which has performed fairly well over the last few years, but we've recently noticed some odd intermittent behaviour in IE8 and IE9. We have a gallery page which calls the image handler multiple times as part of an image's src attribute, this page is opened in a pop up window.

The page works fine when but when the window is opened and closed in quick succession (before all the images on the page have finished loading) it causes the browser to hang and subsequently has to be restarted.

Following is a sample of our image handler code, I have a suspicion that the request to the image isn't 'ending' when the window is closed and the connection between the browser and the server is still running and causing it to crash.

Looking at the logs there are multiple attempts to GET the same image via the handler so it looks like the browser is retrying as it thinks it has failed to complete the request.

Are there any changes I could make to the handler (or the client code) to ensure the browser doesn't continue requesting the images after the window is closed or is this a baked-in intricacy of IE? Safari, Firefox and Chrome handle this type of behaviour fine.

Alos note: The page displaying the images has an update panel around the grid - but I don't think this is related.

Response.Clear();
Response.ContentType = "image/jpeg";
System.Drawing.Image returnImage = System.Drawing.Image.FromFile(completeImageFilePath);
using (MemoryStream stream = new MemoryStream())
{
    returnImage.Save(stream, ImageFormat.Jpeg);
    stream.WriteTo(Response.OutputStream);
}
returnImage.Dispose();
if (Response.IsClientConnected)
{
    Response.Flush();
}
Response.End();
like image 274
Mitul Avatar asked Nov 13 '22 21:11

Mitul


1 Answers

Have you tried wrapping a using around returnImage to "ensure" that .dispose() is called?

Response.Clear();
Response.ContentType = "image/jpeg";
using (System.Drawing.Image returnImage = System.Drawing.Image.FromFile(completeImageFilePath))
{
    using (MemoryStream stream = new MemoryStream())
    {
        returnImage.Save(stream, ImageFormat.Jpeg);
        stream.WriteTo(Response.OutputStream);
    }
}
if (Response.IsClientConnected)
{
    Response.Flush();
}
Response.End();
like image 148
Luke Baughan Avatar answered Nov 15 '22 09:11

Luke Baughan