Reputation: 1332
My .mvc application tries to show a pdf file. It works properly on IE, but fails on Chrome and FF, giving ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
According to similar questions asked here and on other websites, it seems to be a http header problem? When I tried looking at the headers directly, I've found that that responses sent to IE and Firefox differ, as FF gets 3 responses while IE gets 1:
IE response header:
Response HTTP/1.1 200 OK
Cache-Control no-cache, no-store, must-revalidate
Pragma no-cache
Content-Type application/pdf
Expires 0
Server Microsoft-IIS/7.5
X-AspNetMvc-Version 4.0
Content-Disposition inline; filename="Invoice Number US123412.pdf#toolbar=1&view=FitV"
Content-Disposition attachment; filename="Invoice Number US123412.pdf"
X-AspNet-Version 4.0.30319
Persistent-Auth true
X-Powered-By ASP.NET
Date Wed, 19 Apr 2017 12:00:00 GMT
Content-Length 77107
The solution that was given by many people was to add qutation marks ("") around the filename, which I did, but it doesn't seem to help in any way. Here is my header editing code:
Response.AddHeader("Content-Disposition", "inline; filename=\"" + fileName + "#toolbar=1&view=FitV\"");
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.
invoiceHelper.PDF = new InvoicePDF { FileBytes = renderedBytes, FileName = fileName };
return File(renderedBytes, "application/pdf", fileName);
It seems I might be misunderstanding the solution suggested in other threads? Any help would be appreciated.
EDIT:
I should note that I also tried changing the file name to contain no spaces, so that the current response would have Invoice_Number_somenuber12121
EDIT2:
It seems that when I remove my header code, and instead add esponse.ClearHeaders();
, the website loads but the pdf is downloaded instead of being shown
EDIT3: I've found the answer, and so I removed a few parts of this question that weren't significant after all.
Upvotes: 0
Views: 906
Reputation: 1332
I've found the answer. As is often the case, I found it AFTER i posted on stack overflow, not the whole day I was searching for it before that. As seen in the comment to the answer here: Returning a file to View/Download in ASP.NET MVC , the problem lies with the return File(renderedBytes, "application/pdf", fileName);
. The moment you return 3 parameters, the return statement will create its own header. In my case, I just removed the third parameter.
Hint to other people who might have similar problem: try modifying the fileName
variable, or some other variable that is used in your header, to pinpoint the more precise location of the problem.
Upvotes: 1
Reputation: 41997
a) There can only be one response; maybe what you see is a redirect and a new request?
b) In any case, the error code is pretty clear: you are sending multiple Content-Disposition response header fields. Don't. (Note: it's possible that one of those was added by the framework you're using).
Upvotes: 1