Created
December 17, 2013 15:31
-
-
Save christopherhouse/8006791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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