gpt4 book ai didi

c# - 如何强制在 chrome android 上内联打开 pdf 文档?

转载 作者:太空宇宙 更新时间:2023-11-03 15:22:45 24 4
gpt4 key购买 nike

我正在开发 C# ASP.NET Web 应用程序。我们已经创建了一个可以打开 PDF 文档的超链接。 PDF 文档需要在浏览器中内联打开。在桌面上的 Chrome 上它工作正常。在 Android 版 Chrome 上,它会下载 PDF 文档。我该如何修复它才能在两台设备上内联打开 PDF?

这是我的代码:

var document = sessionManager.DocumentServiceClient.GetDocument(documentId, documentStorageType);

this.Response.Clear();
this.Response.ContentType = "application/pdf";
this.Response.AddHeader("Content-Disposition", string.Format("inline; filename = \"{0}.pdf\"", this.DocumentTitle));
this.Response.OutputStream.Write(document.FileData, 0, document.FileData.Length);
this.Response.End();

最佳答案

修复是使用这个内容类型:

this.Response.ContentType = "application/octet-stream";

还需要删除文件名中的空格:

this.Response.AddHeader("Content-Disposition", string.Format("inline; filename = \"{0}.pdf\"", this.DocumentTitle.Replace(" ","")));

关于c# - 如何强制在 chrome android 上内联打开 pdf 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36622938/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com