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);

  • 相关阅读:
    阿里笔试题
    springboot-security-jwt
    java 面试架构篇
    java 面试题 mybatis 篇
    Java 多线程并发工具类
    java 面试题 高阶版
    给你的右键菜单添加“VScode”
    HTML重点知识点汇总
    HTML5知识点小结
    给博客园添加百度统计方法
  • 原文地址:https://www.cnblogs.com/dwfbenben/p/3374110.html
Copyright © 2011-2022 走看看