线程被中止
我正在使用Server.Transfer。一切正常,但异常日志显示以下异常。
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)
at System.Web.HttpServerUtility.Transfer(String path)
任何避免上述异常的想法。
I am using Server.Transfer. Everything works fine, but exception log shows following exception.
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)
at System.Web.HttpServerUtility.Transfer(String path)
Any idea to avoid above exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
此异常是通过调用
Server.Transfer
引发的,以便停止当前方法的执行 - 如果执行Response.Redirect
,也会引发完全相同的情况。你有两个选择:
ThreadAbortException / 重新执行
Server.Transfer
仅在某些地方执行
Server.Transfer
在不会被捕获的地方(推荐)
编辑:从头开始,http://support .microsoft.com/kb/312629 还有一些其他建议可以尝试,但我仍然推荐上面的#2。
This exception is throw by the call to
Server.Transfer
in order to halt the execution of the current method - exactly the same thing gets thrown if you doResponse.Redirect
.The two choices you have are:
ThreadAbortException / reperform the
Server.Transfer
only do
Server.Transfer
in placeswhere it wont be caught (recommended)
EDIT: Scratch that, http://support.microsoft.com/kb/312629 has a couple of other suggestions to try, but I still recommend #2 above.
解决此问题的另一种方法是捕获生成的错误并且不重新抛出它:
Another way to solve this, is to catch the generated error and to not rethrow it:
Caling Server.Transfer 将调用 Response.End,它总是抛出 ThreadAbortException。这是一个“特殊”异常,因为虽然它可以在 catch 块中捕获,但它始终会在 catch 块末尾重新抛出。我会让您的错误日志记录忽略 ThreadAbortExceptions。
Caling Server.Transfer will call Response.End which always throws a ThreadAbortException. This is a "special" exception because while it can be caught in a catch block, it will always be re thrown at the end of the catch block. I would have your error logging ignore ThreadAbortExceptions.
此问题出现在
Response.Redirect
和Server.Transfer
方法中,因为这两个方法都在内部调用Response.End
。该问题的解决方案如下。
对于
Server.Transfer
,请改用Server.Execute
方法。This problem occurs in the
Response.Redirect
andServer.Transfer
methods because both methods callResponse.End
internally.Solution for this Problem is as follows.
For
Server.Transfer
, use theServer.Execute
method instead.将 Response.End() 替换为以下内容有助于解决问题。
响应.Flush();
响应.关闭();
参考我们能否使用Response.Flush()代替Response.End ()
Replacing Response.End() by the following helped fix the problem.
Response.Flush();
Response.Close();
Refer Can we use Response.Flush () instead of Response.End()
将 Response.End() 替换为 HttpContext.Current.ApplicationInstance.CompleteRequest();
Replace
Response.End()
WithHttpContext.Current.ApplicationInstance.CompleteRequest();