Efficient use of Response. Redirect

Source: Internet
Author: User

Introduction:

I am evaluating an ASP. NET Web project application. It has some scalability problems. This means that when the website traffic increases. The system will become slow. When I view the application log. I found a large number of ThreadAbortException. This application uses Response. Redirect (yes, endResponse = true) in large numbers, which is the root cause of the scalability problem. Using endResponse = false in Response. Redirect will solve this problem, but this will cause some strange problems in the application. Because the application will assume that the execution will stop on the current page in Response. Redirect. In addition, you need to handle some security risks, because your application assumes that page events will never be redirected. In this article, I will describe a simple method to solve these problems and achieve good performance.

Note:

For example, if you have a web form, you need to verify some conditions and redirect the user redirect when the conditions do not match.

  Page_Load( condition = (!  btnSave_Click(        }

 

This is good, but it will affect scalability. Because it will terminate the thread pool. now, you only need to use Response. redirect ("Unauthorized. aspx ", false) replace Response. redirect ("Unauthorized. aspx "). this will solve the thread termination problem, but will not stop the current page lifecycle. that is to say, you need to make sure that the btnSave_Click event (and all other page time) can easily send POST requests as long as the btnSave_Click event is allowed to be executed by anyone. to solve this problem, we recommend using the RedirectUser extension method.

     RedirectUser( HttpResponse response,  context = (context !=     Page_Load( condition = (!  btnSave_Click(

 

The first advantage of using RedirectUser is that it will first use the Response. Redirect (with endResponse = false) method with good scalability for the application .. The second advantage is that after you call this method multiple times, it will not overwrite the previous Response. redirect (if any ). the third advantage is that it calls HttpApplication. completeRequest is used to process ASP. all events passed during the NET runtime and HTTP MPs queue information (not page lifecycle MPs queue information ). in addition, check Response in the btnSave_Click event. isRequestBeingRedirected. I also want you to put all internal controls in Response. isRequestBeingRedirected check,

                                                                      

 

Another thing you need to pay attention to is when you use a complex control (like GridView, RadGrid, etc) that has options, inserts, updates, and deletes events. When Response. IsRequestBeingRedirected is true, you must cancel the operations (insert, update, or delete). The following is an example.

 

 

Summary:

In this article, I will show you how to use Response. Redirect. I also found some risk issues. You can use Response. Redirect optimization and technology to reduce risks. I also hope you like this article.

Address: http://weblogs.asp.net/imranbaloch/archive/2013/10/04/using-response-redirect-effectively.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.