0
我有一个简单的操作方法,它返回一个PDF文档,该文档在中以<embed>
标记显示,每调用一次该方法都会返回一个损坏的PDF。 (我已经决定了它的使用开发工具来保存来自服务器的响应损坏)MVC - FileContentResult发送损坏的pdf
操作方法:
public FileContentResult GetPdfReport(string Id)
{
Response.AppendHeader("Content-Disposition", "inline; filename=report.pdf");
var content = System.IO.File.ReadAllBytes(Server.MapPath("~/Reports/Testfile.pdf"));
System.IO.File.WriteAllBytes(Server.MapPath("~/Reports/debugReport.pdf"), content);
return File(content, "application/pdf");
}
查看内容:
<embed id="widgetResponsePdf" src="@Url.Action("GetPdfReport", "WidgetResponse", new { Id = "123" })" type="application/pdf" onmouseout="mouseOutHandler();" />
的文件TestFile.pdf和debugReport当我得到损坏的PDF时,.pdf打开就好,并且正常的请求/响应和损坏的请求/响应之间的请求和响应头没有区别。
在IIS中是否有一些设置可能会导致请求之间的不一致行为,或者这可能仅由网络问题引起?
我不确定,但尝试设置'content.Position = 0;'返回字符串之前 –
谢谢,但内容是一个字节数组,而不是流 –
您确定PDF是否正确?另外,尝试将FileContentResult更改为ActionResult –