我的页面中有一个下载链接,是我通过用户请求生成的文件.现在我想显示文件大小,因此浏览器可以显示剩余的下载量.作为一个解决方案,我想在请求中添加一个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");
}
Run Code Online (Sandbox Code Playgroud)
当我检查fiddler时,它没有显示Content-Length标头.你能帮助我吗?
小智 16
尝试使用
HttpContext.Response.Headers.Add("Content-Length", file.Length.ToString());
Run Code Online (Sandbox Code Playgroud)
Mrc*_*ief 14
尝试 HttpContext.Current.Response.AppendHeader("Content-Length", contentLength);
归档时间: |
|
查看次数: |
69130 次 |
最近记录: |