【发布时间】:2011-12-05 09:01:04
【问题描述】:
我使用下面的代码将文件从 ASP.NET Rest Api 发送到客户端。有时我会看到错误日志“远程主机关闭了连接。错误代码是 0x800703E3。”这是发送流响应的正确方法吗?
var outputFileName;
context.Response.ContentType = WebHelper.GetMimeType(outputFileName);
context.Response.AddHeader("Content-Disposition", string.Format("{0}; filename={1}", "attachment", outputFileName));
context.Response.AddHeader("Content-Length", binaryData.Length.ToString());
context.Response.OutputStream.Write(binaryData, 0, binaryData.Length);
context.Response.Flush();
context.Response.Close();
【问题讨论】:
标签: c# asp.net file httpresponse