在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非常類似的問題,但它沒有解決方案。 –