【发布时间】:2013-04-12 06:12:13
【问题描述】:
我正在使用filestream.write 将数据从服务器流式传输到客户端以供下载。在这种情况下,我可以下载该文件,但它在我的浏览器中没有显示为下载。 “另存为”的弹出窗口都不会出现,“下载栏”也不会出现在“下载”部分。环顾四周,我想我需要在响应标头中包含“某物”,以告诉浏览器此响应有附件。我也想设置cookie。为此,我正在这样做:
[HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" & name)]
public ActionResult Download(string name)
{
// some more code to get data in inputstream.
using (FileStream fs = System.IO.File.OpenWrite(TargetFile))
{
byte[] buffer = new byte[SegmentSize];
int bytesRead;
while ((bytesRead = inputStream.Read(buffer, 0, SegmentSize)) > 0)
{
fs.WriteAsync(buffer, 0, bytesRead);
}
}
}
return RedirectToAction("Index");
}
我收到错误消息:“System.web.httpcontext.current 是一个属性,被用作一种类型。”
我是否在正确的位置更新标题?有没有其他方法可以做到这一点?
【问题讨论】:
标签: c# asp.net-mvc response httpcontext