title: Why is Response.End() not ending the request?
body: <p>I currently have a global error handler set up for my MVC 4 project. We also use this error handler for some web forms projects we have. After it logs the error to the Database and sends an error email to the appropriate people it calls this method which sends our custom error page to the end user.</p>
  
  <pre><code>public static void WriteErrorResponse(string response)
  {
      //Cleanup and send response to user
      HttpContext.Current.Server.ClearError();
      HttpContext.Current.Response.Clear();
      HttpContext.Current.Response.ContentType = "text/html";
      HttpContext.Current.Response.Write(response);
      HttpContext.Current.Response.End();
  }
  </code></pre>
  
  <p>I have come across an instance where our standard error message has not been enough for me to properly track down an issue with one of our sites. So I want to wrap the function definition in a try catch and call this function inside of a catch block. This catch statement looks like this</p>
  
  <pre><code>catch (System.Data.SqlClient.SqlException ex)
  {
          string message = "&lt;strong&gt;Query Executed:&lt;/strong&gt; &lt;br&gt;" + sql + "&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;strong&gt;Query Variables:&lt;/strong&gt;&lt;table&gt;&lt;tbody&gt;";
          foreach(var rv in rvs)
          {
              message += "&lt;tr&gt;&lt;th&gt;" + rv.VariableName + "&lt;/th&gt;&lt;td&gt;" + variables[rv.VariableName] + "&lt;/td&gt;&lt;/tr&gt;";
          }
          message += "&lt;/tbody&gt;&lt;/table&gt;";
          Errors.Error.EmailError(message, ex);
          Errors.Error.LogError(message, ex);
          Errors.Error.Respond500();
          return null;
  }
  </code></pre>
  
  <p>The <code>Errors.Error.Respond500()</code> builds the response string then calls the <code>WriteErrorResponse(string)</code> method displayed above.</p>
  
  <p>All of this actually works, the error message is displayed to the user and I get my more detailed error message. The problem is that the request continues to execute and a second error gets generated due there being an variable being set to null, or trying to set a header after the header has already been sent, etc...</p>
  
  <p>So now I'm left with the question, why is <code>Response.End()</code> not ending the request like the documentation says it should. Also is there a solution to this that doesn't involve me rethrowing the error (2 emails get sent in that situation and that's just annoying!)</p>