"Microsoft Edge PDF内联问题";再次相同的问题 [英] "Microsoft Edge PDF inline issue" Same Issue Again

查看:219
本文介绍了"Microsoft Edge PDF内联问题";再次相同的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然遇到以前在> Microsoft Edge PDF内联中报告和回答的问题问题,即使我没有使用Win 10的预发布版本,但通过Windows Update下载了最新版本.

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.

将Win 8.1机器升级到Win 10,并测试了ASP.NET应用程序后,我遇到了显示嵌入式pdf文件的问题.

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.

这是我的ASP.NET应用程序中的C#代码:

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();

以上内容适用于所有浏览器,但Edge除外,它会给我以下错误:

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

无法打开PDF 某些人无法打开此PDF.

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

我在做什么错了?

推荐答案

从我在连接.

警告:这是一个完整的hack,如果/当Microsoft修复此问题时,可能会造成破坏的危险.

当您查看PDF时,您会看到Edge发出两个请求.在我看来,浏览器正在发送初始请求,然后PDF查看器在打开时发出自己的请求.如果您查看第二个请求中的标头,则会看到一个奇怪的DLNA标头下降,该标头仅用于媒体流,但这使我想到了解决方法...

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. 在处理程序或页面中收到请求时,请检查用户代理字符串是否包含"Edge/12".如果没有,请正常发送PDF.如果是这样,请继续执行步骤2.

  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.

检查HTTP标头"GetContentFeatures.DLNA.ORG"是否存在.如果不是,则表示请求来自浏览器.只需发送回"application/pdf"的Content-Type标头和一个空的正文即可.如果标题存在,则请求来自PDF查看器,您可以正常发送回PDF.

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.

基本上,处理程序将第一个请求视为HEAD请求,然后如果我们确定该请求来自PDF查看器,则使用完整的PDF进行响应.我们在此处运行的风险是,如果Microsoft稍后删除了DLNA标头,Edge将无法正确呈现PDF.希望Microsoft将在其浏览器中解决此问题,并且不需要此解决方法.

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.

这篇关于"Microsoft Edge PDF内联问题";再次相同的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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