void Application_BeginRequest(object sender, EventArgs e) { try { logic.Process(Request, Response, this); } catch (Exception ex) { Server.ClearError(); Response.Clear(); var page = new Http.ErrorPage(Http.ResponseCode.INTERNAL_SERVER_ERROR, "Internal error. (" + ex.Message + ")"); Response.BinaryWrite(System.Text.Encoding.Default.GetBytes(page.ToString())); Response.StatusCode = (int)Http.ResponseCode.INTERNAL_SERVER_ERROR; Response.Flush(); CompleteRequest(); } }