• 由Response.Redirect引发的"Thread was being aborted. "异常的处理方法


    将Response.Redirect写入try...catch会出现异常
    try 

        Response.Redirect(
    "Index.aspx"); 

    catch(Exception e) 

        Response.Redirect(
    "Error.aspx?message=" + e.Message); 

    如上,则会显示"Thread was being aborted. "异常

    同样的还有Response.End()等提前结束当前Theard的方法

    解决方案一:

    如果 Response.Redirect("Index.aspx"); 必须写到Try{}里,则可以在Catch语句写入:

    catch(Exception e) 

        
    if (!(e is ThreadAbortException)) 
        { 
            Response.Redirect(
    "Error.aspx?message=" + e.Message); 
        } 
    }
      略过系统对这个特殊异常的处理。

     解决方案二:

    MSDN已经解析清楚了
    “调用 Redirect 等效于在将第二个参数设置为 true 的情况下调用 Redirect。 Redirect 调用 End,它在完成时引发 ThreadAbortException 异常。” 可见Redirect方法在内部是调用 Thread.Abort()来中止线程的从而引发ThreadAbortException 异常。如果不想立刻中止则,第二个参数设置为false

    C# code

    protected void Button1_Click(object sender, EventArgs e)
    {
    try
    {
    Response.Redirect(
    "A.aspx",false);
    }
    catch( Exception e1)
    {
    Response.Redirect(
    "B.aspx");
    }
    }

     From:

    http://topic.csdn.net/u/20080909/10/fa572c74-5f5b-4996-a649-36691fcfadcb.html

    http://www.zxbc.cn/html/20071128/29848.html

  • 相关阅读:
    图片 滚动切换效果(五) 高级篇
    图片 滚动切换效果(四)
    图片 滚动切换效果(三)
    图片 滚动切换效果(二)
    图片 滚动切换效果(一)
    新年第一篇 之 (摄像机可视区域)
    SuperSocket源码解析之开篇 (转)
    矮人国之战 之 阵型 模仿(二)
    Web Service
    XML于JSON
  • 原文地址:https://www.cnblogs.com/emanlee/p/1334463.html
Copyright © 2020-2023  润新知