在ASP.NET Web窗体中按钮的OnClick方法中,我调用了Response.Redirect()这会导致系统中止该线程并显示错误消息:“抛出的异常:'mscorlib.dll中的'System.Threading.ThreadAbortException'使用Response.Redirect()时
Exception thrown: 'System.Threading.ThreadAbortException' in mscorlib.dll
有类似这样放在这里了几个问题,使用他们的解决方案,我改变了:
Response.Redirect("~/UI/Home.aspx");
到
Response.Redirect("~/UI/Home.aspx", false);
Context.ApplicationInstance.CompleteRequest();
但是我仍然遇到同样的问题。使用调试器,我运行了代码,并且它全部成功执行,直到我调用Response.Redirect();.
的OnClick功能
protected void btnLogin_Click(object sender, EventArgs e)
{
SiteUser s = null;
try
{
string email = txtEmail.Text;
string pwd = txtPwd.Text;
s = DBConnection.login(email, pwd);
}
catch (Exception ex)
{
Console.Write(ex);
lblLoginError.Text = "Error logging in.";
}
if (s != null)
{
Session["UserSession"] = s;
Response.Redirect("~/UI/Home.aspx", false);
Context.ApplicationInstance.CompleteRequest();
}
else
{
lblLoginError.Text = "User not found. Please check your details and try again.";
}
}
为什么这可能发生的任何想法?
'的Response.Redirect()'*真的不应该*给予'FALSE'参数时,抛出该异常... – David
的可能的复制[为什么Response.Redirect的原因System.Threading.ThreadAbortException ?](http://stackoverflow.com/questions/2777105/why-response-redirect-causes-system-threading-threadabortexception) –
@Am_I_Helpful非常类似的问题,但它没有解决方案。 –