c# – Android手机在ASP.Net网站回发后没有打开PDF流
发布时间:2020-12-15 21:22:27 所属栏目:百科 来源:网络整理
导读:我有一个ASP.Net站点,在回发??到初始页面后回流PDF文档.在IE,Chrome,Firefox以及iPhone和iPad上,一切正常,PDF被发送到浏览器.在 Android手机上,我收到一条错误消息,指出PDF无效.下面的代码是我尝试做的简化版本,但它确实重现了错误.我基本上在网页上有一个设
我有一个ASP.Net站点,在回发??到初始页面后回流PDF文档.在IE,Chrome,Firefox以及iPhone和iPad上,一切正常,PDF被发送到浏览器.在
Android手机上,我收到一条错误消息,指出PDF无效.下面的代码是我尝试做的简化版本,但它确实重现了错误.我基本上在网页上有一个设置为在服务器上运行的按钮.在页面的第一个请求中,它显示HTML,在按钮单击后,它应该呈现PDF:
protected void Page_Load(object sender,EventArgs e) { Response.ClearHeaders(); Response.AppendHeader("Cache-Control","no-cache"); //HTTP 1.1 Response.AppendHeader("Cache-Control","private"); // HTTP 1.1 Response.AppendHeader("Cache-Control","no-store"); // HTTP 1.1 Response.AppendHeader("Cache-Control","must-revalidate"); // HTTP 1.1 Response.AppendHeader("Cache-Control","max-stale=0"); // HTTP 1.1 Response.AppendHeader("Cache-Control","post-check=0"); // HTTP 1.1 Response.AppendHeader("Cache-Control","pre-check=0"); // HTTP 1.1 Response.AppendHeader("Pragma","no-cache"); // HTTP 1.1 Response.AppendHeader("Keep-Alive","timeout=3,max=993"); // HTTP 1.1 Response.AppendHeader("Expires","0"); // HTTP 1.1 if (IsPostBack) { Response.ClearContent(); Response.ClearHeaders(); string fullPath = @"C:Tempoutdoc.pdf"; if (System.IO.File.Exists(fullPath)) { //Set the appropriate ContentType. Response.ContentType = "application/pdf"; //Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition","attachment;filename="TestDoc.pdf""); byte[] b = System.IO.File.ReadAllBytes(fullPath); this.Page.Response.AddHeader("Content-Length",b.Length.ToString()); //Write the file directly to the HTTP content output stream. Response.BinaryWrite(b); Response.Flush(); Response.End(); Response.Close(); } } } 我在标题中使用了不同的值,并且在没有运气的情况下关闭和刷新响应流的方式不同.有没有人见过这个或任何人都可以提出任何有关尝试的建议. 编辑:我发现只有当我回发到页面时才会发生这种情况.如果我只是直接将文档流式传输,文档就会正确流式传输.这让我相信它是Android浏览器的某种缓存问题. 解决方法
尝试将当前请求转移到您将PDF直接呈现给响应流的其他处理程序.
您的网页代码: if (IsPostBack) { Context.Server.Transfer("RenderPDF.ashx"); Response.End(); } 在新的RenderPDF.ashx中,移动到负责渲染pdf文件的代码. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |