Since you are using MVC, the best way is to use FileStreamResult
:
return new FileStreamResult(stream, "application/pdf")
{
FileDownloadName = "file.pdf"
};
Playing with Response.Write
or Response.OutputStream
from your controller is non-idiomatic and there's no reason to write your own ActionResult when one already exists.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…