首页 技术 正文
技术 2022年11月15日
0 收藏 530 点赞 4,954 浏览 1149 个字

最近做的系统中老出现的一些问题不太明白,在使用 Response.End、Response.Redirect 或 Server.Transfer 时出现 ThreadAbortException ,

本来系统是没有问题的,在保存数据时也可以正常,本来使用try-catch 语句是用来捕获一异常情况的,但系统正常,老捕获到下面的东西
##[操作记录]:2007-11-23 9:25:12  System.Threading.ThreadAbortException: 正在中止线程。
   在 System.Threading.Thread.AbortInternal()
   在 System.Threading.Thread.Abort(Object stateInfo)
   在 System.Web.HttpResponse.End()
   在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
   在 System.Web.HttpResponse.Redirect(String url)

症状
如果使用 Response.End、Response.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常。您可以使用 try-catch 语句捕获此异常。

 
原因
<!– Inject Script Filtered –>
Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。

此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 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 (“nextpage.aspx”, false);
            如果使用此替代方法,将执行 Response.Redirect 后面的代码。
     对于 Server.Transfer,请改用 Server.Execute 方法。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902