Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Microsoft Edge PDF inline issue" Same Issue Again

I'm still having the same issue that was previously reported and answered under Microsoft Edge PDF inline issue even though I'm not using the pre-release version of Win 10, but the latest downloaded though Windows Update.

After upgrading my Win 8.1 Machine to Win 10, and tested my ASP.NET application, I faced an issue with displaying inline pdf files.

Here's my C# code in my ASP.NET application:

Response.Clear();
Response.ClearHeaders(); 
Response.ClearContent();
Response.ContentType = "application/pdf"; 
Response.AddHeader("content-disposition","inline;filename=some.pdf");
Response.BinaryWrite(pdfArray); 
Response.End();

The above works on all browsers, except on Edge where it gives me the following error:

Couldn’t open PDF Something’s keeping this PDF from opening.

What am I doing wrong?

like image 738
loowool Avatar asked Aug 06 '15 08:08

loowool


1 Answers

Copied from my workaround on Microsoft Connect.

WARNING: This is a complete hack and runs the risk of breaking if/when Microsoft ever fixes this issue.

You'll see that Edge issues two requests whenever you view a PDF. To me, it looks like the browser is sending the initial request and then the PDF viewer is issuing its own request when it is opened. If you look at the headers in that second request, you'll see an odd DLNA header coming down, which should just be for media streaming, but that leads me to my workaround...

  1. When the request is received in your handler or page, check if the user agent string contains "Edge/12." If it doesn't, send your PDF back normally. If it does, move on to step #2.

  2. Check if the HTTP Header "GetContentFeatures.DLNA.ORG" exists. If it doesn't, that means that the request came from the browser. Just send back a Content-Type header of "application/pdf" and an empty body. If the header exists, then the request came from the PDF viewer and you can send your PDF back normally.

Basically, the handler treats that first request as a HEAD request and then responds with the full PDF if we determine that the request is coming from the PDF viewer. The risk we run here is if Microsoft removes that DLNA header later on, Edge will not render the PDF properly. Hopefully, Microsoft will fix this issue in their browser and this workaround will not be necessary.

like image 179
Dark Helmet Avatar answered Oct 19 '22 12:10

Dark Helmet