asp.net - BinaryWrite 与 WriteFile

标签 asp.net

我应该使用什么来将文件写入响应?在我看来,有两种不同的选择。选项一是将文件读入流中,然后将字节写入浏览器

Response.BinaryWrite(new bytes[5])

下一个选项是直接使用 Response.WriteFile 从文件系统写入文件。这两种方法有什么优点/缺点吗?

编辑:更正错别字

最佳答案

如果您在磁盘上有文件并且至少使用 asp.net 2.0,则首选 Response.TransmitFile。

Response.WriteFile 将整个文件读入内存,然后将文件写入响应。传输文件 "Writes the specified file directly to an HTTP response output stream without buffering it in memory."

关于asp.net - BinaryWrite 与 WriteFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/762471/

相关文章:

c# - GridView 中的复选框 "Checked"值始终为 false

c# - ASP.Net MVC : How to read my custom claims value

c# - 尝试通过安全透明方法 'Microsoft.Web.Helpers.PreApplicationStartCode.Start()' 访问安全关键方法

c# - 从另一个项目/dll 引用的 Asp.NET 用户控件具有 NULL 属性

c# - asp.net aspx 的标记验证

ASP.NET MVC 如何禁用自动缓存选项?

asp.net - jQuery FullCalendar点击 'next'事件通知

c# - 如何在 WinXP 中使用 IIS 5.1 发送邮件?

c# - 跳过基于模型属性之一的模型的所有验证 (ASP.Net Core 2.0)

c# - 在 ASP.Net 中使用 AJAX PageMethods 从数据库实现 jQuery AutoComplete TextBox