如果这是ASP.net-Core,则您正在混合使用Web
API版本。让操作返回一个派生,
IActionResult因为在您当前的代码中,该框架被
HttpResponseMessage视为模型。
[Route("api/[controller]")]public class DownloadController : Controller { //GET api/download/12345abc [HttpGet("{id}"] public async Task<IActionResult> Download(string id) { Stream stream = await {{__get_stream_based_on_id_here__}} if(stream == null) return NotFound(); // returns a NotFoundResult with Status404NotFound response. return File(stream, "application/octet-stream"); // returns a FileStreamResult } }


