【发布时间】:2017-05-08 04:38:40
【问题描述】:
症状与C# BinaryWrite over SSL 非常相似,但我的代码已经符合所有建议的解决方案。在撰写本文时,这种行为在 Edge、IE11 和 Chrome 上很明显。在 HTTP 上运行良好的代码在通过 HTTPS 交付时会损坏。
private void RenderPdfToResponse(bool asDownload, byte[] documentBytes)
{
Response.BufferOutput = true;
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Cache-control", "no-store");
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Length", documentBytes.Length.ToString());
if (asDownload)
Response.AddHeader("Content-Disposition",
string.Format("attachment; filename=export{0:yyyyMMddHHmmss}.pdf", DateTime.UtcNow));
Response.BinaryWrite(documentBytes);
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
问题出在浏览器上。应保存到文件中的已交付二进制内容改为在浏览器窗口中呈现。使用调试工具进行拦截并将其保存到文件中可以验证传递的字节是否形成有效的 PDF。
鉴于所引用问题的所有建议都已生效,问题在于浏览器行为,还有哪些选项?
【问题讨论】:
标签: asp.net ssl https content-disposition