asp.net – 来自asp app的流媒体mime类型’application / pdf’在Google Chro
发布时间:2020-05-24 08:24:38 所属栏目:asp.Net 来源:互联网
导读:我有一个Web应用程序,可以在点击事件中流式传输PDF文件,它在IE,Firefox和Safari中运行良好,但在Chrome中它永远不会下载.下载只读“中断”. Chrome处理流媒体有何不同?我的代码看起来像: this.Page.Response.Buffer = true; this.Page.Response.ClearHeaders
|
我有一个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-mvc和webforms共存
- asp.net-mvc – 使用带有MVC3的plupload
- asp.net-core – Visual Studio 2017 RC安装会中断Visual S
- asp.net – 子目录中的Web.config在使用页面路由时不起作用
- asp.net-mvc – Ninject.MVC3,将DependencyResolver传递给服
- asp.net-mvc-3 – ASP.NET MVC3 – Html.TextBoxFor和autof
- asp.net – Web.Config中的Assemblies节点的目的是什么?
- asp.net-mvc – ASP.NET MVC Beta授权属性发送给我错误的动
- asp.net-mvc – 解耦Microsoft.AspNet.Identity.*
- asp.net-mvc – 使用类似MvcContrib Grid的东西在代码可读性
推荐文章
站长推荐
- asp.net – 一个明智的PasswordStrengthRegularE
- asp.net-mvc – JsonSerializer – 使用’N2’格
- asp.net-mvc-4 – 返回状态代码未经授权在WebAPI
- ASP.NET MVC中数据注释的默认资源
- asp.net – 很好的复杂linq到sql示例?
- 选择ASP.NET MVC菜单项
- asp.net-mvc-3 – 为什么ValidationSummary(true
- asp.net-mvc – asp.net mvc中的动态子域
- asp.net-mvc – ASP.NET MVC中的通用基本控制器错
- asp.net – 多个DataContext类是否适合?
热点阅读
