asp.net-mvc – 资源解释为Document但使用MIME类型application/pdf进行传输

请参阅以下代码:

控制器:

public ActionResult GetPDF()
{
    byte[] pdf = GetPdfFromDatabase();
    return new FileContentResult(reportData,"application/pdf");
}

视图:

<iframe src="@Url.Action("GetPDF","Account")" width="600" height="500"></iframe>

Javascript控制台:

Each time you load a page,show this warning !!!

解决方法

谁遇到这个话题. (我也是.)为了获得最佳解决方案,您需要创建HTML页面以充当iframe登录页面以显示PDF内容.

这是示例html.我只是从铬中提取.

<html><body style="background-color: rgb(38,38,38); height: 100%; width: 100%; overflow: hidden; margin: 0px;"><embed width="100%" height="100%" name="plugin" id="plugin" src="your_pdf_url" type="application/pdf"></body></html>

只需将your_pdf_url替换为您的真实网址即可.我只是在Laravel中将此html添加为中间件并显示此HTML,以便Chrome不再发出警告.您可以使用此html作为基础,并创建更好的pdf登录页面,如自定义加载.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....