ASP.NET pages continue to run after page changes?

Asked

Viewed 340 times

7

The method Response.Redirect has a parameter in one of its overloads called endResponse that when true indicates that the current page must be completed after redirecting.

Does this mean that when I do a page redirect (mute page) the previous page will still be occupying space somewhere? It would then be good practice to always use true in this parameter when no longer using the current page?

2 answers

9

That one blog post (in English) explains in detail the situation of the endResponse. In short, the behaviour of close the thread after a redirect was considered a design error, something that is detrimental to the efficiency of ASP [classic] but which was maintained for compatibility reasons. The recommended method for new codes is always to use false, never use true or nothing (i.e. use version without the second parameter - which by default assumes true).

If you want to finish rendering after this redirect (that is, there is nothing else useful for your code to do next) use Context.ApplicationInstance.CompleteRequest().

This means that when I do a page redirect (mute page) the previous page will still be occupying space somewhere?

The thread used to render the previous page still exists somewhere, and can be reused to serve future requests. If you use endResponse true this thread is destroyed and recreated (costly operation), hence the performance problem.

2

When you pass true in the second parameter it calls the Response.End that causes an exception. And according to the documentation This is more damaging to performance than passing false (or nothing).

This Exception has a detrimental Effect on Web application performance, which is Why Passing false for the endResponse Parameter is Recommended.

If the method End fails to cast an exception, it will try to send the entire buffer to the client synchronously which is also harmful to performance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.