zoukankan      html  css  js  c++  java
  • ASP.NET程序中 抛出"Thread was being aborted. "异常(转)

    Thread was being aborted :中文意思 线程被终止

    引用地址:http://support.microsoft.com/default.aspx/kb/312629/EN-US/?p=1

    原因:

    那个 Response.End 方法结束页的执行,并转移到执行 的Application_EndRequest 事件在应用程序的事件管道。该行的代码如下 Response.End 不会被执行。
    此问题出现在 Response.RedirectServer.Transfer方法 方法,因为这两种方法调用 Response.End 在内部。

    解决方案:

    若要解决此问题,请使用下列方法之一:

    • 为了 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法,而不是 Response.End 绕过的代码执行 的Application_EndRequest 事件。

    try{

    HttpContext.Current.Response.ContentEncoding = utf;
               HttpContext.Current.Response.Write(style);
               HttpContext.Current.Response.Write(sb.ToString());
               //HttpContext.Current.Response.End();

    }
    catch{}
    finally
    {
    System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
    }

    • 为了 Response.Redirect,使用过载, Response.Redirect(string URL,bool endResponse) 的推移 false endResponse 参数压制内部电话 Response.End。例如:

        Response.Redirect(“nextpage.aspx”,false);
      						

      如果您使用此解决方案,下面的代码 Response.Redirect 被执行。

    • 为了 Server.Transfer方法,使用 使用Server.Execute 方法来代替。

    另:尽量不要把Response.Redirect("targetUrl");语句写在try里面了! 使用Response.Redirect("targetUrl",false);

  • 相关阅读:
    [洛谷P2184]贪婪大陆
    [BJOI2006]狼抓兔子
    [JSOI2007]重要的城市(x)
    [NOIP2011提高组]Mayan游戏
    gitee 使用
    部分激光打印机清零方法
    django2.0内置分页
    django上下文处理器
    jquery键盘事件
    类视图装饰器
  • 原文地址:https://www.cnblogs.com/dwfbenben/p/3374110.html
Copyright © 2011-2022 走看看