asp.net – 来自asp app的流媒体mime类型’application / pdf’
发布时间:2020-12-15 22:27:02 所属栏目:asp.Net 来源:网络整理
导读:我有一个Web应用程序,可以在点击事件中流式传输PDF文件,它在IE,Firefox和Safari中运行良好,但在Chrome中它永远不会下载.下载只读“中断”. Chrome处理流媒体有何不同?我的代码看起来像: this.Page.Response.Buffer = true; this.Page.Response.ClearHeader
我有一个Web应用程序,可以在点击事件中流式传输PDF文件,它在IE,Firefox和Safari中运行良好,但在Chrome中它永远不会下载.下载只读“中断”. Chrome处理流媒体有何不同?我的代码看起来像:
this.Page.Response.Buffer = true; this.Page.Response.ClearHeaders(); this.Page.Response.ClearContent(); this.Page.Response.ContentType = "application/pdf"; this.Page.Response.AppendHeader("Content-Disposition","attachment;filename=" + fileName); Stream input = reportStream; Stream output = this.Page.Response.OutputStream; const int Size = 4096; byte[] bytes = new byte[4096]; int numBytes = input.Read(bytes,Size); while (numBytes > 0) { output.Write(bytes,numBytes); numBytes = input.Read(bytes,Size); } reportStream.Close(); reportStream.Dispose(); this.Page.Response.Flush(); this.Page.Response.Close(); 关于我可能缺少什么的任何建议? 解决方法
最新的Google Chrome v12版本
introduced a bug会触发您描述的问题.
您可以通过发送Content-Length标头来修复它,如下面的代码修改版本所示: this.Page.Response.Buffer = true; this.Page.Response.ClearHeaders(); this.Page.Response.ClearContent(); this.Page.Response.ContentType = "application/pdf"; this.Page.Response.AppendHeader("Content-Disposition","attachment;filename=" + fileName); Stream input = reportStream; Stream output = this.Page.Response.OutputStream; const int Size = 4096; byte[] bytes = new byte[4096]; int totalBytes = 0; int numBytes = input.Read(bytes,Size); totalBytes += numBytes; while (numBytes > 0) { output.Write(bytes,numBytes); numBytes = input.Read(bytes,Size); totalBytes += numBytes; } // You can set this header here thanks to the Response.Buffer = true above // This header fixes the Google Chrome bug this.Page.Response.AddHeader("Content-Length",totalBytes.ToString()); reportStream.Close(); reportStream.Dispose(); this.Page.Response.Flush(); this.Page.Response.Close(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 使用MVC2的AJAX请求中的CSRF保护
- asp.net-mvc – 在nopcommerce 2.8中使用Telerik插件的自定
- 单元测试 – Stubbing或Mocking ASP.NET Web API HttpClien
- asp.net-mvc – 存储库模式中的纯POCO实体更新问题
- 成员资格 – 如何在ASP.NET中将用户与其各自的文件夹连接起
- asp.net-mvc-3 – Structuremap,AutoFac或Ninject,哪一个适
- asp.net – 处理您的请求时发生异常.此外,执行自定义错误页
- ASP.Net控件如何从其数据源读取?
- asp.net – COM异常 – TYPE_E_CANTLOADLIBRARY?
- asp.net-mvc – Asp.net MVC真的消除了viewstate吗?
推荐文章
站长推荐
- .net – 从页面后面的代码中调用User Control中的
- asp.net – 你如何’规范’一个Web服务器来支持给
- asp.net-mvc – 尝试创建类型为’TypeNewsContro
- asp.net-mvc – 适用于asp.net MVC和razor视图的
- asp.net-mvc-3 – 我应该尝试使用MVC3和ASP.net的
- asp.net – Web API的XML帮助文档未在发布时更新
- asp.net-mvc-4 – 使用angularjs和ASP.NET MVC
- asp.net-mvc – ASP.NET MVC FluentValidation P
- asp.net-mvc – 如果是流媒体,则无法发布网站
- 通过扩展让ASP.NET Web API支持JSONP
热点阅读