What is the difference between / used use cases Response.End (false) and ApplicationInstance.CompleteRequest ()

I came across a SO question that discussed usage ApplicationInstance.CompleteRequest()

to avoid getting ThreadAbortException

thrown when called Response.End()

.

In the past, in order to avoid errors of exclusion referred to above, I've used this overload: Response.End(false)

.

I am trying to understand what are the differences between these two methods. Why did I choose to use ApplicationInstance.CompleteRequest()

instead Response.End(false)

?

EDIT:

I realize that ApplicationInstance.CompleteRequest()

is the more correct way to do things, but the only function that is missing when called Response.End(true)

is the not that handles the rest of the following code. Sometimes we don't want to continue processing, but we want to end the execution right there and then.

Possibly answering my own question here, but perhaps the correct way to do this is to write code so that there are no more lines of code processed when the response ends (and the stream is not interrupted).

Example:

[DO SOME WORK]
if ([SOME CONDITION])
{
     ApplicationInstance.CompleteRequest();
}
else
{
    //continue processing request
}

      

It might work, but it looks like we are coding here to deal with the limitations of the method. And it can lead to incorrect code.

Did I miss something?

+3


source to share


1 answer


http://weblogs.asp.net/hajan/archive/2010/09/26/why-not-to-use-httpresponse-close-and-httpresponse-end.aspx

From the article: "Instead of using the HttpResponse.End and HttpResponse.Close methods, it is best to use the HttpApplication.CompleteRequest method, so that the response data that is buffered on the server, client, or in between will receive."

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Hello Hajan");
    Response.End();            
    Response.Write("<br />Goodbye Hajan");
}
Output: Hello Hajan

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Hello Hajan");
    this.Context.ApplicationInstance.CompleteRequest();
    Response.Write("<br />Goodbye Hajan");
}

Output: Hello Hajan 
Goodbye Hajan

      



http://blogs.msdn.com/b/aspnetue/archive/2010/05/25/response-end-response-close-and-how-customer-feedback-helps-us-improve-msdn-documentation.aspx

From the article: "HttpApplication.CompleteRequest is the best way to complete a request."

+3


source







All Articles