Displaying images returned as ActionResult (byte array) causes IE6 to freeze

旧城冷巷雨未停 提交于 2019-12-10 13:03:20

问题


Microsoft MVC, C#, IIS, CSS question.

I have a problem with the following scenario in IE6:

I have a View that would display a variable number of images, each image returned from the controller side as a BinaryResult.

These BinaryResult objects are then assigned to the src attribute of the img elements in the page.

Example, if I load a page which has N number of images in it, I would be making N number of controller calls to get these images. These images are just very small thumbnails and in a page there could only be a maximum number of 40 thumbnails.

This approach seem to work fine in IE8, IE7.

However, in IE6, it would only load initially. If I move away from the page then move back, the image loading would cause Ie6 to freeze up. ( well, basically you can leave it for an hour after which it would be responsive -- but the images are not displayed at all).

Initially- I defaulted to stripping down the CSS (thinking its IE6.. but it seemed to work fine if I display images that were not retrieved via BinaryResult).

Also, IIS server settings for compression as well as IE6 browser memory settings were tweaked.

Could really appreciate any help -- if anyone out there has experienced a similar problem.


回答1:


Not sure what the issue might be but try this:

public ActionResult Image()
{
    byte[] image = FetchImage();
    return File(image, "image/png"); // adjust content type appropriately
}

And in your view:

<img src="<%= Url.Action("Image") %>" alt="" />



回答2:


Use this code in controller:

public FileStreamResult ShowImage()
{
     MemoryStream ms = new MemoryStream();
     //
     // Create Image
     //
     ms.Position = 0;

     return new FileStreamResult(ms, "image/jpeg");
}

and here is the code for img tag:

<img src="~/YourController/ShowImage" />


来源:https://stackoverflow.com/questions/3545811/displaying-images-returned-as-actionresult-byte-array-causes-ie6-to-freeze

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