void ContextError(object sender, EventArgs args) { var httpApplication = sender as HttpApplication; var httpContext = httpApplication.Context; httpContext.Response.Clear(); var exception = httpContext.Server.GetLastError(); var statusCode = GetStatusCode(exception); var errorLoggingContext = new ExceptionLoggingContext(httpContext, statusCode, exception); var exceptionHandlingContext = new ExceptionHandlingContext(httpContext, statusCode, exception, this.LogException); if (this.handlers.ContainsKey(statusCode)) { try { httpContext.Server.ClearError(); this.handlers[statusCode](exceptionHandlingContext); return; } catch (Exception e) { LogException(new ExceptionLoggingContext(httpContext, HttpStatusCode.InternalServerError, e)); } } LogException(errorLoggingContext); try { DefaultAction(exceptionHandlingContext); httpContext.Server.ClearError(); } catch (Exception e) { LogException(new ExceptionLoggingContext(httpContext, HttpStatusCode.InternalServerError, e)); HttpContext.Current.Response.StatusCode = 500; } }
protected abstract void DefaultAction(ExceptionHandlingContext context);