Reputation: 3794
I have a PDF file save in my server. Now I'm trying to return this file as a Content-Disposition=inline.
So I wrote this:
public FileResult Test()
{
var ms = new MemoryStream();
using (var fs = new FileStream(@"C:\Users\Me\Desktop\test.pdf", FileMode.Open))
{
fs.CopyTo(ms);
}
ms.Position = 0;
Response.AppendHeader("Content-Disposition", "inline; filename=test.pdf");
return File(ms, "application/pdf");
}
But in my browser (Chrome) I get a empty pdf. I tried other browsers and get this:
And I have another page in my application that is using pretty much the same code and works for all browsers.
Anyone can help me to understand why this strange behavior in some browsers and others not?
UPDATE
I tried to change my PDF in this code (like the same code but another pdf) and works for all browsers.
So is it possible that the content of the PDF is causing that? I tried and both pdfs are open fine in Adobe Reader and Win 8 Default PDF Reader.
As @Odrai request I tried too:
Response.AppendHeader("content-disposition", "attachment; filename=test");
But didn't work too and change the way that file is received (with attachment the browser make a download instead to open the file). I need to open in inline mode.
As @dustmouse request I tried to open the pdfs directly in the browsers and the same problem occurs.
So now I understand it's not a program problem, I intend to close this question. But before that is there other place that I can put this question (like other forum related with stackoverflow, i.e. code review or something)?
Upvotes: 0
Views: 878
Reputation: 3794
As was explained in here by @AaronSieb:
This appears to be a bug in recent versions of Chrome. It was reported on October 14th, 2015 and appears to be fixed in recent builds.
For me, updating to Chrome 46.0.2490.80 solved the issue.
Source: https://code.google.com/p/chromium/issues/detail?id=543018
Upvotes: 1