Error: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
Cause of Error:
When we call Response.Redirect("") from try/catch block in asp.net, you will receive above error.
Example contains error:
try
{
string strRedirectUrl = Session["ReturnUrl"].ToString();
Response.Redirect(strRedirectUrl);
}
catch(Exception ex)
{
Response.Redirect("Default.aspx");
}
Solution:
Make second argument of response.redirect("MyPage.aspx",false);
Example containing solution:
try
{
string strRedirectUrl = Session["ReturnUrl"].ToString();
Response.Redirect(strRedirectUrl,false);
}
catch(Exception ex)
{
Response.Redirect("Default.aspx");
}
For More details Response.Redirect(url,true) Vs Response.Redirect(url,false);
1 comment:
This has helped a great deal. Thanks for your input and time to post this..
Post a Comment