在 ASP.NET Web 表单中按钮的 OnClick 方法中,我调用了 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();。
点击功能
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.";
}
}
关于为什么会发生这种情况的任何想法?