Precautions for resolving Response. Redirect ThreadAbortException exceptions

Source: Internet
Author: User

Precautions for ASP. NET to solve Response. Redirect ThreadAbortException exceptions
By kaleyroy, 21 reading, 0 Comments, favorites, Edit
 
ASP. NET Response. redirect () is used to jump to the page. there is no need to explain this too much. the ThreadAbortException exception is thrown when you use a try catch block. Many solutions have been mentioned on the internet. Below I will refer to the solution officially recommended by MS.


For Response. end, call the HttpContext. current. applicationInstance. completeRequest method instead of Response. end to bypass the code execution to the Application_EndRequest event. for Response. redirect, use an overload, Response. redirect (String url, bool endResponse) that passes false for the endResponse parameter to suppress the internal call to Response. end.

For example:

Response. Redirect ("nextpage. aspx", false );
                           

If you use this workaround, the code that follows Response. Redirect is executed.
For Server. Transfer, use the Server. Execute method instead. You have noticed that the red text indicates that if it is set to false:

Response. Redirect ("nextpage. aspx", false );

The subsequent code will continue to be executed, so we should note this!


 

So we:


1. If you want to completely intercept the code after the jump, we recommend that you put Response. Redirect out of try catch or use another better method!

2. When Response. Redirect is set to false, remember that the code behind you will still be executed. Do not let it affect your business processing and use it with caution.

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.