Click here to Skip to main content
15,665,942 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Response Redirect Throw Exception as Thread Exception as

Unable to Evaluate Expression because the code is optimized or a native frame is on top of the call stack

What I have tried:

I have tried Response.Redirect("/", false). Which is not executes since Endresponse is false it will not call redirect.
Updated 21-Jan-19 2:13am
ZurdoDev 21-Jan-19 7:17am    
As I recall, you can ignore that error. It's because you are ending the current thread by going somewhere else. Just google the error number and you'll see that you can catch that error and ignore it.

1 solution

Fought this a few years ago, was getting a ThreadAbort Exception.

Option 1 is to wrap it in a Try...Catch block and ignore it. Generally I do not catch exceptions and ignore, but this case is special
try { Response.Redirect(url); }
catch (ThreadAbortException) {/* no real action performed */}

Option 2 is to allow the thread to continue executing after the redirect, best to do the redirect as the last part of a process. Otherwise there could be performance impacts.
Response.Redirect(url, false);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900