gpt4 book ai didi

c# - 如何在 ASP.NET MVC 3 中的 HTTPContext 响应中添加 header ?

转载 作者:可可西里 更新时间:2023-11-01 08:15:22 26 4
gpt4 key购买 nike

我的页面中有一个下载链接,指向我根据用户请求生成的文件。现在我想显示文件大小,以便浏览器可以显示还剩多少下载。作为一种解决方案,我想在请求中添加一个 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");
}

当我检查 fiddler 时,它没有显示 Content-Length header 。你们能帮帮我吗?

最佳答案

尝试使用

HttpContext.Response.Headers.Add("Content-Length", file.Length.ToString());

关于c# - 如何在 ASP.NET MVC 3 中的 HTTPContext 响应中添加 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6539342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com