Skip to content

Instantly share code, notes, and snippets.

@christopherhouse
Created December 17, 2013 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopherhouse/8006791 to your computer and use it in GitHub Desktop.
Save christopherhouse/8006791 to your computer and use it in GitHub Desktop.
protected void Application_Error(object sender, EventArgs e)
{
Exception lastError = Server.GetLastError();
Server.ClearError();
int statusCode = 0;
if (lastError.GetType() == typeof(HttpException))
{
statusCode = ((HttpException) lastError).GetHttpCode();
}
else
{
// Not an HTTP related error so this is a problem in our code, set status to
// 500 (internal server error)
statusCode = 500;
}
HttpContextWrapper contextWrapper = new HttpContextWrapper(this.Context);
RouteData routeData = new RouteData();
routeData.Values.Add("controller", "Error");
routeData.Values.Add("action", "Index");
routeData.Values.Add("statusCode", statusCode);
routeData.Values.Add("exception", lastError);
routeData.Values.Add("isAjaxRequet", contextWrapper.Request.IsAjaxRequest());
IController controller = new ErrorController();
RequestContext requestContext = new RequestContext(contextWrapper, routeData);
controller.Execute(requestContext);
Response.End();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment