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.