ASP.NET How To Stream File To User

前端 未结 1 1212
北荒
北荒 2020-11-27 20:01

Initially I was trying to figure out what the difference is between Response.Close and Response.End, but after doing more googling and research, its clear that I haven\'t se

相关标签:
1条回答
  • 2020-11-27 20:28

    I wouldn't call Response.Close() or Response.End().

    Response.End() will stop the page execution/rendering at that point. No code following Response.End() will be run. The response is terminated at that point with no further output added to the stream.

    Response.Close() is similar to Response.End(), but allows code to be executed after it is called (but no further output can be sent in the page response).

    Response.Flush() will send any remaining response items to the page.

    From an IIS core team member:

    Response.Close sends a reset packet to the client and using it in anything other than error condition will lead to all sorts of problems - eg, if you are talking to a client with enough latency, the reset packet can cause any other response data buffered on the server, client or somewhere in between to be dropped.

    In this particular case, compression involves looking for common patterns within the response and some amount of response has to be buffered by the compression code to increase the chance of finding longer repeating patterns - this part that is buffered cannot be sent to the client once you do Response.Close().

    In short, do not use Response.Close().

    0 讨论(0)
提交回复
热议问题