asp.net - 有没有办法强制 MS Edge 在自身内部打开 Excel 文件而不是下载它?

标签 asp.net excel http microsoft-edge attachment

在我的组织中,使用 MS Edge 作为默认浏览器,有一个定期更新且经常打开的 Excel 电子表格,我们将其托管在内部 IIS 服务器上,并从另一个内部 ASP.NET 网站链接到该电子表格,该网站也在IIS。 每次有人单击该链接时,该文件都会再次下载,并且必须在用户的 Excel 桌面副本中手动打开,即使 Edge 现在可以查看 MS Office 文件(通过 Office Web 应用程序)并且此设置由默认。 Edge 中的“在浏览器中打开 Office 文件”选项是否启用与发生的情况无关。拖放或按 Ctrl+O-ing 下载的文件只会使 Edge 再次“下载”它。

我的问题在这里:

  • Edge 究竟如何决定它可以打开哪些 MS Office 文件?是否仅支持某些版本的 Office?我尝试了默认的 .xlsx 文件类型和 Office 97-2003 .xls,具有相同的效果;该文件可能没有任何格式错误或特殊,因为我的测试文件几乎是带有一个文本单元格的空电子表格
  • 是否有某种机制可以强制浏览器尝试打开它支持的文件,类似于download的相反内容a 上的属性标签? Content-Disposition: inline似乎是我正在寻找的内容,但是检查网络选项卡中的下载显示该 header 不存在,因此 inline应为默认值。
  • 我曾考虑过嵌入 OneDrive 中存储的文档副本,但此功能似乎已被弃用。是这样吗?或者组织可以禁用它?

作为最后的手段,我们可以将文档存储为 PDF(本质上是只读的)。

尝试过:

  • 使用 group policy/registry key 强制启用“在浏览器中打开 Office 文件”选项
  • 只需打开文件链接
  • 使用 Edge 打开本地存储的 Excel 文件

每个人都使用其 Microsoft 帐户登录 Office 365,我也看到这是一项要求。

期望:

  • 使用 Edge 的 Office 查看器功能在新选项卡中向用户显示 Excel 文件

现实:

  • Excel 文件已下载

最佳答案

“在浏览器中打开 Office 文件”此功能适用于受以下限制的公共(public)可访问的 Office 文档。您可以引用this article并检查您的 Excel 文件是否符合要求:

The OpenInOfficeViewerIfApplicable feature watches navigations to detect when Office-related file extensions (.xls, .docx, pptx, etc) or Content-Types (application/msword, application/vnd.ms-excel, etc) are observed, indicating that a navigation led directly to an Office document that would otherwise be deemed as having a non-webby MIME type and thus normally be converted into a download.

The feature is bypassed if:

  1. The Open Office files in the browser checkbox is turned off in edge://settings
  2. The response contains a Content-Disposition:attachment header
  3. The request contains an Authorization or Proxy-Authorization header
  4. The user initiated the download from the “Save As” item on the browser’s context menu
  5. The referring URL is on a limited set of exempted domains (Office, SharePoint, OneDrive, Blackboard, etc)
  6. The request method is not GET
  7. The file size is not known (e.g. Transfer-Encoding: chunked)
  8. The file size is over 100mb
  9. The browser is running in Incognito mode
  10. The file was served from an IP address that is not publicly routable

关于asp.net - 有没有办法强制 MS Edge 在自身内部打开 Excel 文件而不是下载它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77273048/

相关文章:

asp.net - 如何在文本框上使用 RegularExpressionValidator

c# - 将 GridView 导出到 excel 并将 excel 文件保存到文件夹

jquery - 为什么Application_ResolveRequestCache的持续时间很长?

php - 在 Symfony 数据库中导入 Excel 数据

ASP.NET ActionFilters 和继承

c# - 检测 Excel 工作簿链接

VBA比较多个变量

QT http 设置用户代理

c# - 414 - 请求的 uri 太长 - url 长度为 70 个字符

linux - "curl: (48) An unknown option was passed in to libcurl"