症状

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

 

原因

Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。

此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 Response.End

 

解决方案

要解决此问题,请使用下列方法之一:
 
1.  对于 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 以跳过 Application_EndRequest 事件的代码执行。
2.  对于 Response.Redirect,请使用重载 Response.Redirect(String url, bool endResponse),该重载对 endResponse 参数传递 false 以取消对 Response.End 的内部调用。例如:

  Response.Redirect ("nextpage.aspx", false);            

如果使用此替代方法,将执行 Response.Redirect 后面的代码

 
3. 对于 Server.Transfer,请改用 Server.Execute 方法。
 
 
引用:http://blog.sina.com.cn/s/blog_67a3453d0101bn2b.html
 
 

System.Threading.ThreadAbortException: 正在中止线程的更多相关文章

  1. C#错误之 System.Threading.ThreadAbortException:正在中止线程

    参考:http://www.cnblogs.com/chendaoyin/archive/2013/06/27/3159211.html 1.开启一个子线程 //开启一个子线程,子线程调用方法 Met ...

  2. C# 关闭进程的时候总是捕捉到System.Threading.ThreadAbortException: 正在中止线程

    C# 关闭进程的时候总是捕捉到System.Threading.ThreadAbortException: 正在中止线程 这是由ThreadAbortException抛出的 可以写成下面的样子 tr ...

  3. System.Threading.ThreadAbortException: 正在中止线程。

    在 System.Threading.ThreadAbortException 中第一次偶然出现的"mscorlib.dll"类型的异常 "System.Threadin ...

  4. 【异常记录(九)】 System.Threading.ThreadAbortException: 正在中止线程

    报错如下: System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Thread.Ab ...

  5. “System.Threading.ThreadAbortException”类型的第一次机会异常在 mscorlib.dll 中发

    问题原因: Thread.Abort 方法 .NET Framework 4  其他版本   1(共 1)对本文的评价是有帮助 - 评价此主题 在调用此方法的线程上引发 ThreadAbortExce ...

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

    第一次遇到这样的错误 错误语法 try{ Response.Redirect("aa.aspx"); }catch (Exception ex){ Response.Redirec ...

  7. ASP.NET: 正在中止线程 错误原及解决方法

    #[操作记录]:2010-02-23 9:25:12  System.Threading.ThreadAbortException: 正在中止线程. 症状 如果使用 Response.End.Resp ...

  8. 【转】ASP.NET"正在中止线程"错误原因

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

  9. 异常System.Threading.Thread.AbortInternal

    异常信息: System.Threading.ThreadAbortException: 正在中止线程. 在 System.Threading.Thread.AbortInternal() 在 Sys ...

随机推荐

  1. 2018.10.25 bzoj3928: [Cerc2014] Outer space invaders(区间dp)

    传送门 区间dpdpdp好题. 首先肯定需要把坐标离散化. 然后在数轴上面区间dpdpdp. 对于当前区间,区间中最大的数一定会被选. 于是我们记f[i,j]f[i,j]f[i,j]表示所有左端点在i ...

  2. pat -1004(树的遍历)

    题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805521431773184 思路: (1)用vector记录每 ...

  3. MySQL处理表字段小技巧

    MySQL利用正则函数替换值 update dateTest set date=REPLACE(date,'/','') where date REGEXP '\/'; SQL语句讲解: -- 将 所 ...

  4. excel中vba求摩尔圆包线

    Dim f As Double, f1 As Double, f2 As Double, df As Double, oxy() As Double, R() As Double, k As Doub ...

  5. what is a resolver

    resolver [rɪ'zɒlvə] 解析器 ViewResolver The ViewResolver provides a mapping between view names and actu ...

  6. Python 安装requests和MySQLdb

    Python 安装requests和MySQLdb 2017年10月02日 0.系统版本 0.1 查看系统版本 [root@localhost ~]# uname -a Linux localhost ...

  7. split(),reverse(),join()

     split() 通过把字符串分割成子字符串来把一个 String 对象分割成一个字符串数组. str.split([separator][, limit])示例: "Webkit Moz ...

  8. Windows 8.1 Update中的小改变

    在Build 2014大会中,发布了Windows 8.1 Update的更新,并将于4月8日通过Windows Update进行推送.但是,在MSDN订阅下载中,带有该更新的镜像已经可以在4月3号放 ...

  9. 14:super关键字

    本小节知识点: 1.super基本概念 2.super的作用 1.super基本概念 super是个编译器的指令符号,只是告诉编译器在执行的时候,去调谁的方法. self是一个隐私参数; self r ...

  10. C++ 中的continue理解

    continue的在循环中的作用: 1. 跳过当前循环,但是还需要执行自增条件, 如下程序:当i == 3时,执行i++, 即if判定{}执行完毕,则i==4, 然后 for最后一条语句i++, 然后 ...