在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作。

如果将Response.End()放在try...catch中,catch会捕捉Thread.CurrentThread.Abort()产生的异常System.Threading.ThreadAbortException。

解决方法(任选一个):

1. 在catch中排除ThreadAbortException异常,示例代码如下:

在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作
try
{
    Response.End();
}
catch (System.Threading.ThreadAbortException)
{
}
catch (Exception ex)
{
    Response.Write(ex);
}
在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作

2. 用Context.ApplicationInstance.CompleteRequest()结束当前请求,代码如下[经测试这个不可以用]:

在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作
protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        Response.Write("Hello world!");
        this.Page.Visible = false;
        Context.ApplicationInstance.CompleteRequest();
    }
    catch (Exception ex)
    {
        Response.Write(ex);
    }
}

相关文章:

  • 2022-03-08
  • 2021-11-16
  • 2021-06-19
  • 2021-05-22
  • 2022-12-23
  • 2021-08-18
  • 2021-12-23
  • 2022-01-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
相关资源
相似解决方案