When response. Redirect is put in try catch, the following error occurs:
Unable to evaluate expression because the code is optimized or a native frame is on top of the Call Stack Try
{
Dosomething ();
Response. rediret ("A.html");
}
Catch {}
Check it. It turns out that response. Redirect will call respons. End () by default, and the respons. End method will stop page execution and transform the execution to the application.ProgramThe application_endrequest event in the event pipeline, soCode(In fact, the code after response. End) will not be executed.
Solution: Call the response. Redirect overload function response. Redirect (string URL, bool endresponse). The parameter is false.
If there is response. End () in try, the solution is to use applicationinstance. completerequest instead of response. End to avoid the application_endrequest event.