zoukankan      html  css  js  c++  java
  • 【转】ASP.NET"正在中止线程"错误原因

    最近做的系统中老出现的一些问题不太明白,在使用 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 方法。

  • 相关阅读:
    poj 1200 crasy search
    cdoj 1092 韩爷的梦
    fzu 2257 saya的小熊饼干
    zoj 3950 how many nines
    zoj 3963 heap partion
    fzu 2256 迷宫
    fzu 2253 salty fish
    hdu 2473 Junk-Mail Filter
    codeforces 129B students and shoes
    hdu 3367 Pseudoforest
  • 原文地址:https://www.cnblogs.com/hycms/p/4200382.html
Copyright © 2011-2022 走看看