Is ASP.NET MVC's FileStreamResult less efficient than writing directly to the Response Output Stream, or am I missing something?

前端 未结 2 1636
攒了一身酷
攒了一身酷 2021-02-06 01:55

First of all, I love ASP.NET MVC. This question is not a criticism of it. Rather, I want to confirm what I think I see and make sure I haven\'t missed something. Bear w

2条回答
  •  隐瞒了意图╮
    2021-02-06 02:34

    I believe it would be more accurate to say that, assuming someObjectThatDumpsOutputToWhateverStreamYouHandIt does not inherit from System.IO.Stream, that using FileStreamResult forces you to either

    a) implement a wrapper for someObjectThatDumpsOutputToWhateverStreamYouHandIt that does inherit from System.IO.Stream, or

    b) use a temporary MemoryStream instance.

    So, it is not necessarily less efficient, but does seem to require a bit more work for the purpose of returning a value.

    Edit by Question Asker: I am choosing this question as the Accepted answer. Both responses were very helpful. I have to choose one, and this one pointed me to Phil Haack's DelegatingActionResult, which is exactly what I needed.

提交回复
热议问题