Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome, pdf display, Duplicate headers received from the server

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"); 
like image 572
BlairM Avatar asked Dec 21 '11 11:12

BlairM


2 Answers

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) 
like image 95
2GDave Avatar answered Sep 17 '22 22:09

2GDave


I used @roryok's comment, wrapping the filename in quotes:

Response.AddHeader("content-disposition", "attachment; filename=\"" + FileName + "\"") 

@a coder's answer of using single quotes did not work as expected in IE. The file downloaded with the single quotes still in the name.

like image 22
Homer Avatar answered Sep 16 '22 22:09

Homer