"Aborting thread" error generated by Response.Redirect
Source: Internet
Author: User
"Aborting thread" error generated by Response.Redirect
Today, during development debugging, a "aborting thread" exception message appears.
Call Response.Redirect () method generated, although know is the problem of threading, but I do not know why Redirect will appear such a mistake, has not been encountered before,
After a baidu,google, it was found that Ms had already solved the problem, but provided a solution.
Abnormal
If you use the Response.End, Response.Redirect, or Server.Transfer method, a ThreadAbortException exception appears. You can use the Try-catch statement to catch this exception.
Reason
The Response.End method terminates the execution of the page and switches this execution to the Application_EndRequest event in the application's event pipeline. The line of code following the Response.End is not executed.
This problem occurs in the Response.Redirect and Server.Transfer methods because both of these methods call Response.End internally.
Solution
To resolve this issue, use one of the following two methods:
For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of the Response.End method to skip Application_ Code execution for the EndRequest event.
For Response.Redirect, use the overloaded Response.Redirect (String URL, bool endresponse) method, which passes false to the Endresponse parameter to cancel the Internal call to the Response.End. For example: Response.Redirect ("microscopelist.aspx", false);
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.