MVC FileResult and Performance?
In ASP.NET WebForm开发者_Python百科s, I normally prefer to use Response.TransmitFile instead of Response.WriteFile as the former hands off the work of sending the file to the operating system instead of tying up the application, and leads to more scalable aplications.
Does anyone know whether the MVC FileContentResult follows the same efficient approach?
If you’ve got a physical location to a file that you want to return to the client, you can use the FilePathResult class. It will simply call Response.TransmitFile and pass it the path you’ve previously sent into its constructor.
Ref: https://msmvps.com/blogs/luisabreu/archive/2009/02/12/the-mvc-platform-working-with-files.aspx
From the source code it writes directly to the stream :
protected override void WriteFile(HttpResponseBase response) {
response.OutputStream.Write(FileContents, 0, FileContents.Length);
}
精彩评论