解决IE无法加载图片,其他浏览器可以加载的问题

最近遇到一个问题网站利用<img src=”‘showlocalimage.ashx?path=SlidePath ‘”>的方法加载显示图片,但是其他浏览器都可以正常显示,IE忽然就不行了,以前IE也是可以的,因为懒得深究,如果有人知道告诉我一声。

网上的办法都是设置图片模式什么,但是需要动态加载的图片往往都是用户上传的,高要求图片也不切实际,所以想要采用base64,不过asp不太会用,然后发现bite[]可以,好开心,想来分享的时候,才发现原来 真正发挥作用的是context.Response.ContentType = “image/png”;简单的说 必须要与图片原来的类型对应。。。
所谓原来的类型就是说,比如我把png认为改成了jpg,他还是要写成png,不过这个额 用户应该不会这么闲,也懒得管了。

string imgpath = context.Request[“path”];
if (!string.IsNullOrEmpty(imgpath))
{
if (System.IO.File.Exists(imgpath))
{
var lstex = new string[] { “.png”, “.jpg”, “.jpeg”, “.gif”, “.bmp” };
var indexofEx = imgpath.LastIndexOf(’.’);
var ex = imgpath.Substring(indexofEx);
context.Response.ContentType = “image/” + ex.Replace(“.”, “”).Replace(“jpg”, “jpeg”);
if (lstex.Contains(ex.ToLower()))
{
context.Response.WriteFile(imgpath);
context.Response.Flush();
}
}
}
context.Response.End();

    原文作者:JJBDXX
    原文地址: https://blog.csdn.net/qq_34348615/article/details/90647335
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞