Response.Redirect的和线程已被中止错误? [英] Response.Redirect and thread was being aborted error?

查看:279
本文介绍了Response.Redirect的和线程已被中止错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在错误日志中有这样错误的线程已被中止。后,今天下午。

I had this error Thread was being aborted., this afternoon in my error log.

这是导致该错误的code是:

The code that caused this error is:

Response.Redirect("Login.aspx", true);

如果我修改布尔,错误日志为空,但此错误停止再来,但程序停止工作。

If I change the bool value to false, the error log becomes empty and this error stops coming again, but the program stops working.

如果我把它这样,我得到这个错误,如滋扰。

If I keep it as such, I am getting this error like nuisance.

我想知道使用替代的Response.Redirect 通过真正作为值 endResponse 参数。

I want to know the alternative for using Response.Redirect passing true as the value for the endResponse parameter.

推荐答案

我赶上这种异常并吞下它,因为ASP.NET使用流量控制例外,而不是一个特殊的情况。

I catch this exception and swallow it because ASP.NET is using exceptions for flow control rather than for an exceptional circumstance.

try
{
    // Do stuff.
}
catch(ThreadAbortException)
{
    // Do nothing. ASP.NET is redirecting.
    // Always comment this so other developers know why the exception 
    // is being swallowed.
}
catch(OtherExceptionTypes ex)
{
    // Log other types of exception.
}

这篇关于Response.Redirect的和线程已被中止错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆