【问题标题】:HTTPS content-disposition attachmentHTTPS 内容处置附件
【发布时间】: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


    【解决方案1】:

    咨询https://www.rfc-editor.org/rfc/rfc6266我们发现文件名部分是可选的。实验指定

    Response.AddHeader("Content-Disposition", "attachment");
    

    导致所有主要浏览器弹出一个名为 export-pdf.pdf 的“另存为”对话框,该对话框显然源自 ASPX 文件的名称和 mime 类型。

    此时我被要求发货。我希望有人觉得这很有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 2012-02-04
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      相关资源
      最近更新 更多