【发布时间】:2020-03-13 02:06:53
【问题描述】:
我的页面中有一个下载链接,指向我根据用户请求生成的文件。现在我想显示文件大小,这样浏览器就可以显示还有多少要下载。作为一种解决方案,我想在请求中添加一个 Header 会起作用,但现在我不知道该怎么做。
这是我的尝试代码:
public FileStreamResult DownloadSignalRecord(long id, long powerPlantID, long generatingUnitID)
{
SignalRepository sr = new SignalRepository();
var file = sr.GetRecordFile(powerPlantID, generatingUnitID, id);
Stream stream = new MemoryStream(file);
HttpContext.Response.AddHeader("Content-Length", file.Length.ToString());
return File(stream, "binary/RFX", sr.GetRecordName(powerPlantID, generatingUnitID, id) + ".rfx");
}
当我检查提琴手时,它没有显示 Content-Length 标头。你们能帮帮我吗?
【问题讨论】:
标签: c# asp.net-mvc-3