线程被中止

发布于 2024-08-05 11:30:22 字数 446 浏览 8 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

如若梦似彩虹 2024-08-12 11:30:22

此异常是通过调用 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 do Response.Redirect.

The two choices you have are:

  • Catch and rethrow the
    ThreadAbortException / reperform the
    Server.Transfer
  • Make sure that you
    only do Server.Transfer in places
    where 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.

淤浪 2024-08-12 11:30:22

解决此问题的另一种方法是捕获生成的错误并且不重新抛出它:

        catch (ThreadAbortException)
        { 
        }

Another way to solve this, is to catch the generated error and to not rethrow it:

        catch (ThreadAbortException)
        { 
        }
东走西顾 2024-08-12 11:30:22

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.

那些过往 2024-08-12 11:30:22

此问题出现在 Response.RedirectServer.Transfer 方法中,因为这两个方法都在内部调用 Response.End

该问题的解决方案如下。

对于Server.Transfer,请改用Server.Execute 方法。

This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.

Solution for this Problem is as follows.

For Server.Transfer, use the Server.Execute method instead.

梦与时光遇 2024-08-12 11:30:22

将 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()

美胚控场 2024-08-12 11:30:22

将 Response.End() 替换为 HttpContext.Current.ApplicationInstance.CompleteRequest();

Replace Response.End() With HttpContext.Current.ApplicationInstance.CompleteRequest();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文