RSo*_*erg 6 c# asp.net download httpresponse
最初我试图找出Response.Close和Response.End之间的区别,但是在进行了更多的谷歌搜索和研究后,很明显我没有看到Byte []被发送回客户端的常见方式.我将在下面留下代码示例,但我想知道行业标准是做什么的.
Byte[] myBytes = GetReportBytes();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AppendHeader("content-length", myBytes.Length.ToString());
HttpContext.Current.Response.AppendHeader("content-Disposition", "attachment;filename=" + this.ReportFileName + GetReportExtension());
HttpContext.Current.Response.ContentType = GetApplicationContentType();
HttpContext.Current.Response.BinaryWrite(myBytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
//CERT FIX
//HttpContext.Current.Response.End();
Run Code Online (Sandbox Code Playgroud)
Mit*_*eat 17
我不打电话Response.Close()或Response.End().
Response.End()将在此时停止页面执行/呈现.不会Response.End()运行以下代码.响应在该点终止,没有进一步的输出添加到流.
Response.Close()类似于Response.End(),但允许代码在被调用后执行(但在页面响应中不能再发送输出).
Response.Flush() 将任何剩余的响应项发送到页面.
来自IIS核心团队成员:
Response.Close向客户端发送重置数据包,并在除错误条件之外的任何其他情况下使用它将导致各种问题 - 例如,如果您正在与具有足够延迟的客户端通信,则重置数据包可能导致任何其他响应数据被缓冲在服务器,客户端或其间的某个地方被删除.
在这种特殊情况下,压缩包括在响应中查找常见模式,并且压缩代码必须缓冲一定量的响应,以增加找到更长重复模式的机会 - 缓冲的这部分一旦你无法发送到客户端做Response.Close().
简而言之,不要使用Response.Close().
| 归档时间: |
|
| 查看次数: |
12111 次 |
| 最近记录: |