显示Base64String,因为图像适用于IE但不适用于Chrome [英] Showing Base64String as Image works in IE but not in Chrome

查看:924
本文介绍了显示Base64String,因为图像适用于IE但不适用于Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#代码:
public ActionResult GetDoucmentImage(long onBaseDocumentId)
{
onBaseDocumentId = 1111;
OnBaseDataAccess db = new OnBaseDataAccess();
OnBaseDocument document = db.GetDocument(onBaseDocumentId);
return View(GetDoucmentImage,document);
}

查看代码:

  @{
   var base64 = Convert.ToBase64String(Model.Data);
   var imgSrc = String.Format("data:image/png;base64,{0}", base64);}
   <img src="@imgSrc" style="width:200px; height:400px;"/>

尝试在浏览器中显示图像,它可以在IE中使用,但不能在Chrome中使用

Trying to show an image in browser, it works in IE but not in chrome

推荐答案

使用铬,选择你的图像元素并右键单击并从上下文菜单中选择检查元素....

using chromium, select your image element and right click and select the "Inspect Element" from the context menu....

chrome Developer工具将打开并突出显示图像元素的客户端来源....

the chromium Developer tool will open and highlight the client source of the image element....

比较src值与在IE Developer工具中显示(f12> Find选项卡)....

compare the src value with that shown in the IE Developer tool (f12>Find tab)....

我认为MSIE和Gecko浏览器清理base64编码(toStaticHTML),以防止恶意脚本注入。 ..

I think MSIE and Gecko browsers sanitise base64 encodings (toStaticHTML), to prevent malicious script injections...

也许您的Model.Data实际上不是一个png图像。

Maybe your Model.Data is not actually a png image.

这篇关于显示Base64String,因为图像适用于IE但不适用于Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆