SoFunction
Updated on 2025-03-08

Aborting thread solution

During the development and debugging process in the past two days, an exception message of "ThreadAbortException" always appears.
Exceptions are generated by methods. Although they know it is a thread problem, somehow Redirect has such an error. I have never encountered it before, and it was encountered when it was transferred to 2.0 development.
After Googled it for a while, I found out that MS had discovered this problem long ago, but provided a solution. Here is a summary of the main information:
symptom
If you use the , or method, a ThreadAbortException exception will appear. You can use the try-catch statement to catch this exception.
reason
The method terminates the execution of the page and switches this execution to the Application_EndRequest event in the application's event pipeline. Don't execute the following line of code.

This problem occurs in the and methods, because both methods are called internally.
Solution
To resolve this issue, use one of the following methods: • For , call the method instead of code execution that skips the Application_EndRequest event.
• For , use an overload (String url, bool endResponse), which passes false to the endResponse parameter to cancel the internal call to . For example: ("", false);

B-E-A-utiful! It's that simple, the problem is solved, thanks to Microsoft, thanks to GOOGLE, thanks to God!

Now post the solution, hoping to help more people solve similar problems encountered during the development process and carry out the search to the end!