小编Joe*_*eld的帖子

使用 Response.Redirect() 时“抛出异常:mscorlib.dll 中的‘System.Threading.ThreadAbortException’”

在 ASP.NET Web 表单中按钮的 OnClick 方法中,我调用了 Response.Redirect(),这会导致系统中止线程并显示错误消息:

Exception thrown: 'System.Threading.ThreadAbortException' in mscorlib.dll
Run Code Online (Sandbox Code Playgroud)

这里有一些与此类似的问题,使用我更改的解决方案:

Response.Redirect("~/UI/Home.aspx");
Run Code Online (Sandbox Code Playgroud)

Response.Redirect("~/UI/Home.aspx", false);
Context.ApplicationInstance.CompleteRequest();
Run Code Online (Sandbox Code Playgroud)

但是我仍然遇到同样的问题。我使用调试器运行了代码,一切都成功执行,直到我调用 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 …
Run Code Online (Sandbox Code Playgroud)

c# asp.net exception mscorlib threadabortexception

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

asp.net ×1

c# ×1

exception ×1

mscorlib ×1

threadabortexception ×1