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

北城余情 提交于 2019-12-07 05:45:16

问题


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();

回答1:


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();


来源:https://stackoverflow.com/questions/12788597/multiple-image-handler-calls-causing-ie-to-hang-in-pop-up-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!