首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Response.BinaryWrite在MAC中不与Safari合作

Response.BinaryWrite在MAC中不与Safari合作
EN

Stack Overflow用户
提问于 2012-01-03 09:52:43
回答 1查看 2.4K关注 0票数 0

我使用以下代码将PDF发送到浏览器

代码语言:javascript
复制
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Length", fileBytes.Length.ToString());
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(fileBytes);
        Response.Flush();
        System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();

除了MAC中的Safari (Version5.x)之外,它对所有浏览器都很好(pdf被正确地嵌入到浏览器中)。同时,它也能正常工作在MAC中的Firefox和Chrome上。

我想知道这是浏览器问题吗?或者Response.BinaryWrite有什么问题?

编辑

Safari行为,pdf根本不加载。一个进度条显示并继续加载,可能是与安装的PDF插件有关吗?那么,如何在Safari中找到这种行为的原因呢?

编辑

此错误登录在Safari Developer Tools控制台中,“未能加载资源:插件处理加载”,这似乎与PDF插件有关。

EN

回答 1

Stack Overflow用户

发布于 2012-01-03 11:18:48

试试这个,它和我一起工作很好

代码语言:javascript
复制
        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "application/pdf";
        Response.Buffer = true;
        Response.AppendHeader("Accept-Header", attachmentObj.AttachmentFile.Length.ToString());
        Response.AppendHeader("content-disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(attachmentObj.Description, System.Text.Encoding.UTF8) + "\"");
        Response.AppendHeader("Pragma", "public");
        Response.BinaryWrite((byte[])attachmentObj.AttachmentFile.ToArray());        
        Response.Flush();
        Response.End();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8710395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档