Asp.net is using response. Redirect try {} catch {} block failure (zt)

Source: Internet
Author: User

Http://www.cnblogs.com/jkswjw/archive/2009/03/05/1403639.html

Try
{

...
Response. Redirect ("/Mymaimai. aspx ");
...
}
Catch (exception E)
{
// Exception Handling

}


If you use the preceding statements, system. Threading. threadabortexception will be thrown regardless of whether an exception exists.
:
The response. End method stops page execution and converts the execution to the application_endrequest event in the event pipeline of the application. The code lines after response. End are not executed.

This problem occurs in the response. Redirect and server. transfer methods, because both methods call response. End internally.

Solution

To solve this problem, use one of the following methods:

For response. End, call applicationinstance. completerequest instead of response. End to skip the code execution of the application_endrequest event.

For response. Redirect, use the overload response. Redirect (string URL, bool endresponse) to pass false to the endresponse parameter to cancel internal calls to response. End. For example:

Response. Redirect ("/mymaimai. aspx", false); if this solution is used, the Code following response. Redirect will be executed.

For server. Transfer, use the server. Execute method.

Status

This phenomenon is caused by design.

Code after solution
:
Try
{
Response. Redirect ("/mymaimai. aspx"
, False );
}
Catch
{
// Exception Handling

}

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.