asp.net出现的异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值" 的解决方法

引用: https://support.microsoft.com/zh-cn/kb/312629

症状
如果您使用的Response.End、 Response.Redirect或Server.Transfer方法,将引发异常时发生。您可以使用try-catch语句可以捕捉此异常。
原因
Response.End方法结束执行页,并将执行切换到应用程序的事件管道中的Application_EndRequest事件。按照Response.End的代码的行不会被执行。

因为这两种方法都会内部调用Response.End , Response.Redirect和Server.Transfer方法中发生此问题。
解决方案
要解决此问题,请使用下列方法之一:
  • 对于 Response.End调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 若要跳过对代码执行 Application_EndRequest 事件。
  • 对于 Response.Redirect使用重载时, Response.Redirect (url 字符串、 布尔值 endResponse) 传递 假 对于 endResponse 若要取消内部调用的参数 Response.End.例如:
    
      Response.Redirect ("nextpage.aspx", false);
    						
    如果您使用此替代方法,该代码的后面 Response.Redirect 执行。
  • 对于 Server.Transfer使用 Server.Execute 方法相反。
原文地址:https://www.cnblogs.com/peasana/p/4686573.html