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


First of all, I do not have any criticism about this question as love asp.NET MVC. Instead, I want to confirm what I am thinking and I will ensure that I have not left anything. Stay with me ... I can not go on without question providing a little context.

In response to an HTTP post, you have to query the data back into a stream, in the earlier days of ASP.NET MVC, you can do your data directly by piping in the Response stream. For example, you can do something like this:

  Some Objects DumpApotputTovAstream UIHDact. Write (Response .uputup stream);  

See the main aspect of this code: I did not apply any backing store I did not need to stream information in the byte array, Instead of dump into the temporary file, ASP.Net had already installed a stream for the purpose of communicating the response in the browser, and I have put that stream directly into that stream. In the case of CPU, memory and execution time, it is more efficient than copying all the data from some temporary location and moving it into the response stream.

However, this unit is not very suitable for tests. In fact, you can still do such code in ASP.NET MVC, but it will be to avoid custom. Rather, ASP.NETT MVC will encourage you to return an action-salts. Action Roustal is an ASP.Net MVC concept that is mostly unit test friendly. This allows you to "declare" what you did. A unit test can use a controller action and confirms that it receives the required anchorslust. That unit can run outside the test browser.

ASP.NET MVC provides a kind of action to return the streams of data. This is called filestream result. Make the name "filename" stupid. It's about returning a stream of data, as we are talking about above.

However, here's the problem, and the basis of my question: If you make your controller method then FileStreamResult, and you assign it to a stream that you want to return It appears that there is no way to dump your data directly into the Response stream. Now, it seems that you need to dump your stream into a backing store (such as memory or a file), your data in it, and then the stream that you return to FileStreamResult.

It seems that I have to do something like this (deliberately omitting disposal / using / etc):

  MemoryStream myIntermediateStream = new MemoryStream (); Some ObjectTitDotputsToViewstream UIHiteSite (MyInterDietist Stream); New FileStream RET Refund (MyInterDiTestStream, "App / PDF");  

Note that my intrinsistim data causes the reasons for temporarily storing the contents of large streams of data, so that the filestream result can be copied to the Response Output stream later.

So my question is: did I ignore something, or is it true that for using the filestream result you are forced to get an intermediate storage space, if Do you have to write directly to the Response Output Stream?

Thank you.

I believe this would be more accurate to say that, some objectatted DumpApotputTovAstream EHold and It does not get the heir to the system.iostream, which you use either

A) to apply the cover for some objectatted display by using the filestream result. Apply also here is a stream System.IO.stream, or

b) Use a temporary MemoryStream example .

Therefore, it is not neces generally less efficient, but the purpose of returning the value requires some more work.

Edit by Asking Questions: I am choosing this question as an approved answer. Both responses were very useful, I had to choose one, and it told me about Phil Hake's Delegating Action Resolve, which is exactly what I want.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -