title: "Exception thrown: 'System.Threading.ThreadAbortException' in mscorlib.dll" when using Response.Redirect()
body: <p>In an OnClick method for a button in an ASP.NET web form I have a call to Response.Redirect() which causes the system to abort the thread with the error message: </p>
  
  <pre><code>Exception thrown: 'System.Threading.ThreadAbortException' in mscorlib.dll
  </code></pre>
  
  <p>There's a few questions similar to this on here, using their solutions I changed:</p>
  
  <pre><code>Response.Redirect("~/UI/Home.aspx");
  </code></pre>
  
  <p>to </p>
  
  <pre><code>Response.Redirect("~/UI/Home.aspx", false);
  Context.ApplicationInstance.CompleteRequest();
  </code></pre>
  
  <p>However I am still getting the same problem. Using the debugger I ran through the code and it all executed successfully until I called Response.Redirect();.</p>
  
  <p><strong>OnClick Function</strong></p>
  
  <pre><code>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.";
          }
      }
  </code></pre>
  
  <p>Any thoughts on why this might be happening?</p>