Exemplo n.º 1
0
 /// <summary>
 /// Executes when Unhandled Exception is thrown.
 /// </summary>
 /// <param name="context">ActionExecuted Context</param>
 public override void OnException(HttpActionExecutedContext context)
 {
     DiagnosticsProvider diagnostics = new DiagnosticsProvider(this.GetType());
     Exception exception = context.Exception;
     diagnostics.WriteErrorTrace(TraceEventId.Exception, exception);
     context.Response = context.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message);
 }
Exemplo n.º 2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            // Get the error details
            Exception ex = Server.GetLastError();

            // Check exception type and default Http 500 (internal server error)
            Response.StatusCode = (ex is HttpException) ? (ex as HttpException).GetHttpCode() : (int)HttpStatusCode.InternalServerError;

            // Log exception
            DiagnosticsProvider diagnostics = new DiagnosticsProvider(this.GetType());
            string error = string.Join("\n", "Unhandled Exception: ", ex.ToString());
            diagnostics.WriteErrorTrace(TraceEventId.Exception, error);

            // Clear buffers
            Server.ClearError();
            Response.End();
        }