异常:由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。

来源:互联网 发布:js获取a标记的href 编辑:程序博客网 时间:2024/05/01 04:12

转自:http://blog.csdn.net/lizhao1226/article/details/6236810

及转自:http://blog.csdn.net/zhensoft163/article/details/5448597

try {     Response.Redirect("httpHandler.ashx"); } catch{        //此处异常必定会执行throw new Exception("异常");} 

原因:

如果使用 Response.End、Response.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常。此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 Response.End。Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。


解决方法:

• 对于 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 以跳过 Application_EndRequest 事件的代码执行。(此方法还未尝试过,暂时用不到

 对于 Response.Redirect,请使用重载 Response.Redirect(String url, bool endResponse),该重载对 endResponse 参数传递 false 以取消对 Response.End 的内部调用。例如:

Response.Redirect ("httpHandler.ashx", false);//此方法已亲测过,可以解决问题



0 0
原创粉丝点击