我在我的 asp.net 应用程序中收到一个错误
“无法评估表达式,因为代码已优化或 native 框架位于调用堆栈的顶部。”
protected void btnCustomerProfile_Click(object sender, EventArgs e)
{
try
{
Server.Transfer("CustomerProfile.aspx");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{ }
}
搜索SO后,看到类似的帖子大多涉及response.redirect。我的代码使用的是 server.transfer,我的应用程序也使用母版页。
我该如何解决这个问题?
更新: 出于某种原因,发生此错误是因为我也使用 Response.Redirect。不幸的是,我不能使用 Server.Execute,因为 Server.Execute 会在最后调用调用页面。
最佳答案
你会得到一个错误,但下面的代码块会捕获它,你可以继续你的生活。
试试这个:
using System.Threading.ThreadAbortException;
catch(ThreadAbortException ex)
{
throw;
}
关于c# - 错误 : Unable to evaluate expression because the code is optimized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10982949/