Asp.net fails to use response. Redirect try {} catch {} Block

Source: Internet
Author: User

 

Try
{

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

}


Use the preceding statement , Whether or not exceptions exist , All Catch In , Always show "" Failed "" Will throw system. Threading. threadabortexception, The reason is as follows:
:
response. end the method stops page execution, convert the execution to application_endrequest event. response. end Code lines following the "> will not be executed.

This problem occurs inResponse. RedirectAndServer. TransferMethod, because both methods are called internallyResponse. End.

Solution

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

for response. end , call applicationinstance. completerequest method without calling response. end , to skip applicatio N_endrequest Event code execution.

For Response. Redirect , Use overload Response. Redirect (string URL, bool endresponse) Endresponse It is passed False To cancel Response. End . For example:

Response. Redirect ("/Mymaimai. aspx", False );If you use this solution,Response. RedirectThe subsequent code will be executed.

ForServer. Transfer, UseServer. ExecuteMethod.

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.