Is Response.End() considered harmful?

前端 未结 9 768
陌清茗
陌清茗 2020-11-22 01:01

This KB Article says that ASP.NET\'s Response.End() aborts a thread.

Reflector shows that it looks like this:

public void End()
{
            


        
9条回答
  •  感情败类
    2020-11-22 01:52

    On the question of "I still don't know the difference between Response.Close and CompleteRequest()" I would say:

    Do prefer CompleteRequest(), don't use Response.Close().

    See the following article for a well-done summary of this case.

    Be aware that even after calling CompleteRequest() some text (e.g. redndered from ASPX code) would be appended to the response output stream. You can prevent it by overriding Render and RaisePostBackEvent methods as described in the following article.

    BTW: I agree with preventing of using Response.End(), especially when writing data to the http stream to emulate file download. We've used the Response.End() in the past until our log file became full of ThreadAbortExceptions.

提交回复
热议问题