先重现问题

1、新建一个aspx页面项目,插入两个页面WebForm1.aspx,WebForm2.aspx,

WebForm1代码修改如下

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        Response.Redirect("WebForm2.aspx");
    }
    catch (Exception exception)
    {
        Console.WriteLine(exception);
        throw;
    }
}

2、在浏览器中打开WebForm1.aspx,页面正常跳转到了WebForm2.aspx,但是如果在以下代码加上断点的话,会有Thread was being aborted异常抛出
C# Thread was being aborted

 

 3、问题原因
response.redirect();

response.write();

response.end();

会导致当前进程Abort,线程中止,Abort导致异常,虽然这个问题对实际代码运行没有影响,但是如果使用日志系统的话,会导致日志文件中有大量的Error错误。

4、解决办法
修改代码如下
C# Thread was being aborted

 

 或者
C# Thread was being aborted

 

相关文章:

  • 2022-03-07
  • 2021-07-28
  • 2021-08-29
  • 2021-09-28
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2022-01-15
  • 2021-07-24
  • 2021-09-15
相关资源
相似解决方案