【发布时间】:2018-09-24 19:06:45
【问题描述】:
我正在使用 ASP.NET Core 2.1 ActionResult
[HttpGet]
public ActionResult<FileResult> Download()
{
var someBinaryFile = "somebinaryfilepath";
return File(new FileStream(firstExe, FileMode.Open, FileAccess.Read, FileShare.Read), System.Net.Mime.MediaTypeNames.Application.Octet, true);
}
但它返回不完整的 json 而不是开始下载文件:
{"fileStream":{"handle":{"value":2676},"canRead":true,"canWrite":false,"safeFileHandle":
{"isInvalid":false,"isClosed":false},"name":"somebinaryfilepath","isAsync":false,"length":952320,"position":0,"canSeek":true,"canTimeout":false
Chrome devtools 将请求状态指示为“(失败)”,工具提示为“net::ERR_SPDY_PROTOCOL_ERROR”
如果我更改代码使其返回 FileContentResult,则状态变为“200 ok”,但仍写入 json 而不是文件下载:
{"fileContents": "somebinaryfilecontent","contentType":"application/octet-stream","fileDownloadName":"","lastModified":null,"entityTag":null,"enableRangeProcessing":true}
如果我将方法签名更改为
public FileResult Download()
或者去
public IActionResult Download()
然后文件下载从两个 FileResult 实现开始。
如何使用 ActionResult
【问题讨论】:
标签: c# asp.net-core asp.net-core-2.1