static void FinishWithException (HttpWorkerRequest wr, HttpException e)
{
int code = e.GetHttpCode ();
wr.SendStatus (code, HttpWorkerRequest.GetStatusDescription (code));
wr.SendUnknownResponseHeader ("Connection", "close");
Encoding enc = Encoding.ASCII;
wr.SendUnknownResponseHeader ("Content-Type", "text/html; charset=" + enc.WebName);
string msg = e.GetHtmlErrorMessage ();
byte [] contentBytes = enc.GetBytes (msg);
wr.SendUnknownResponseHeader ("Content-Length", contentBytes.Length.ToString ());
wr.SendResponseFromMemory (contentBytes, contentBytes.Length);
wr.FlushResponse (true);
wr.CloseConnection ();
HttpApplication.requests_total_counter.Increment ();
}