Response.Redirect 和线程被中止错误? [英] Response.Redirect and thread was being aborted error?
问题描述
我有这个错误线程被中止.,今天下午在我的错误日志中.
I had this error Thread was being aborted., this afternoon in my error log.
导致这个错误的代码是:
The code that caused this error is:
Response.Redirect("Login.aspx", true);
如果我将 bool
值更改为 false
,错误日志变为空并且此错误不再出现,但程序停止工作.
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
传递 true
作为 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屋!