首页 > 解决方案 > 某些 pdf 文件未在 chrome 中完全加载

问题描述

我在网站上有大约 100 个 pdf 文件,在昨天之前它们都运行良好。

从昨天开始,一些文件将无法完全加载,只有第一页会以 chrome 显示。

有几点需要注意:

  1. 所有 pdf 在除 chrome 之外的所有浏览器中仍然可以正常工作。
  2. 我将所有文件和数据库复制到临时站点,所有 pdf 在包括 chrome 在内的所有浏览器中都可以正常工作。登台站点位于同一台服务器上。
  3. 有时未加载的文件会加载,但随后会再次损坏。我无法确定它发生的原因。
  4. 没有创建/显示 pdf 的代码,打开 pdf 的链接仅指向服务器上的实际 pdf 位置。
  5. 当 pdf 未加载时,控制台日志中显示的唯一内容是以下警告:

A cookie associated with a cross-site resource at "" was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.

我尝试添加 cookieSameSite="Strict" 和 Lax,但它并没有解决问题。

任何帮助,将不胜感激。

标签: asp.netgoogle-chromepdf

解决方案


我无法弄清楚这个问题,但是在我更改代码以使用 Asp.Net 打开 pdf 后,问题得到了解决。

这是我添加的代码示例:

Response.Clear();
string filePath = "/downloads/" + Request.QueryString["file"];
Response.ContentType = "application/pdf";
Response.WriteFile(filePath);
Response.End();

推荐阅读