我有一个应用程序,我正在使用亚马逊S3作为文件服务器使用EF和C#构建。我所做的是,我上传了一些PDF的S3和存储在我的数据库中的网址,然后在应用程序中显示它。我使用会话将模型传递给视图,然后使用For Each
遍历网址,并为每个网址创建一个新的iframe
,如下所示:
@{int i = 1;}
@foreach (var tempimg in (List<TempImage>)Session["TempImages"])
{
<fieldset class="invoiceFieldsets" data-step="@i" id="FieldSet_@i" hidden>
<div class="row">
<div class="col-xs-4">
<div class="fixed-actions invoiceContainer">
<div class="card text-center" id="Picture_@i" style="width:450px;height:500px;background-color:ghostwhite;border:none">
@*<div class="card-header">
Profit and Loss
</div>*@
<input type="hidden" id="ImagePath_@i" runat="server" value="@tempimg.ImagePath" hidden />
<div class="card-body" display="inline-block" id="imagepreview_@i" style="background-image:url(@tempimg.ImagePath)" hidden>
<iframe id="pdfviewer_@i" src="@tempimg.ImagePath" style="width:500px; height:500px;" sandbox="allow-same-origin" hidden></iframe>
@*<embed width="500" height="500" name="plugin" id="pdfviewer_@i" src="@tempimg.ImagePath" type="application/pdf">*@
</div>
</div>
</div>
</div>
根据该值(即,如果返回的URL包含.pdf),我隐藏或取消隐藏iframe
var imgtype = $("#ImagePath_"+current).val();
if (imgtype.indexOf(".pdf") >= 0) {
$("#pdfviewer_"+current).prop('hidden', false);
$("#pdfviewer_"+current).attr('src', imgtype);
}
else {
$("#imagepreview_"+current).prop('hidden', false);
}
我一直有的问题是,图片显示正确,但PDF不显示。我确实从谷歌收到了CORBS的警告,但我甚至尝试过绕过它,但它仍然不起作用。你能在这方面帮我吗?
发布于 2019-10-07 19:26:38
我找到问题了。在定义iframe
时,我发现代码sandbox="allow-same-origin"
的这一部分导致了这个问题。一旦我移除它,它就开始工作了。我希望这对其他正在经历同样问题的人有所帮助。
https://stackoverflow.com/questions/58218306
复制相似问题