c# - 错误 : Unable to evaluate expression because the code is optimized

标签 c# asp.net master-pages server.transfer

我在我的 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/

相关文章:

c# - .NET 迁移 : Setup and migrate multiple databases at runtime

javascript - 在 ContentPage 中使用 Javascript 更改 <body> ID

asp.net - MVC4,两种不同的母版

html - <div> 中的 3 列

c# - 在 C# 中将 CSS 分配给动态创建的标签

c# - ASP.Net 中的数据缓存与 session 对象

c# - Check.Assert()、Check.Ensure() 和 Check.Require() 有什么作用?

c# - 从以编程方式创建的按钮事件调用函数

c# - 添加缺失的 html 标签

c# - 使用 C# 的字符串数组的总和