Chrome浏览器,PDF格式显示,从服务器接收重复标头 [英] Chrome, pdf display, Duplicate headers received from the server

查看:300
本文介绍了Chrome浏览器,PDF格式显示,从服务器接收重复标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我展示灯箱里面的PDF上的一节。最近升级的Chrome已经打破了这一显示:


  

错误349(净值:: ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION):
  我们收到了多个内容处置头。我们不允许此
  防止HTTP响应拆分攻击。


这仍然正常工作在IE中。

我使用ASP.NET MVC3在IIS6

在code我用它来生成文件如下。

如果我删除了inline语句然后将该文件下载,但是,打破了收藏夹功能。

问题code

 公共FileResult的PrintService()
{
    // ...无关code删除
    MemoryStream的MemoryStream的=新的MemoryStream();
    pdfRenderer.PdfDocument.Save(MemoryStream的);
    字符串文件名=ServicesSummary.pdf;    Response.AppendHeader(内容处置,内联;);    返回文件(memoryStream.ToArray(),应用程序/ PDF,文件名);
}


的修复

删除

  Response.AppendHeader(内容处置,内联;);

然后更改

 返回文件(memoryStream.ToArray(),应用程序/ PDF,文件名);

 返回文件(memoryStream.ToArray(),应用程序/ PDF格式);


解决方案

解决方案上面是好的,如果你不需要指定文件名,但我们想保持对用户指定的文件名默认值。

我们的解决方案,结束了文件名本身,因为它包含了一些逗号。我做了更换用,逗号和文件现在提供如预期在Chrome中的文档。

 文件名= FileName.Replace(,)Response.ContentType =应用程序/ PDF
Response.AddHeader(内容处置,附件;文件名=&安培;文件名)
Response.BinaryWrite(myPDF)

I have a section on a website where I display a pdf inside a light box. The recent chrome upgrade has broken this displaying:

Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Multiple Content-Disposition headers received. This is disallowed to protect against HTTP response-splitting attacks.

This still works correctly in IE.

I'm using ASP.NET MVC3 on IIS6

The code I use to generate the file is as follows.

If I remove the inline statement then the file downloads, however that breaks the lightbox functionality.

Problem Code

public FileResult PrintServices()
{
    //... unrelated code removed
    MemoryStream memoryStream = new MemoryStream();
    pdfRenderer.PdfDocument.Save(memoryStream);
    string filename = "ServicesSummary.pdf";

    Response.AppendHeader("Content-Disposition", "inline;");

    return File(memoryStream.ToArray(), "application/pdf", filename);
}


The Fix

Remove

Response.AppendHeader("Content-Disposition", "inline;");

Then Change

return File(memoryStream.ToArray(), "application/pdf", filename);

to

return File(memoryStream.ToArray(), "application/pdf");

解决方案

The solution above is fine if you don't need to specify the filename, but we wanted to keep the filename default specified for the user.

Our solution ended up being the filename itself as it contained some commas. I did a replace on the commas with "" and the file now delivers the document as expected in Chrome.

FileName = FileName.Replace(",", "")

Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=" & FileName)    
Response.BinaryWrite(myPDF)

这篇关于Chrome浏览器,PDF格式显示,从服务器接收重复标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆