Showing Base64String as Image works in IE but not in Chrome

隐身守侯 提交于 2019-12-13 03:03:48

问题


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

View Code:

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

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


回答1:


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

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

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

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

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



来源:https://stackoverflow.com/questions/27114759/showing-base64string-as-image-works-in-ie-but-not-in-chrome

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