Created
February 10, 2011 22:35
-
-
Save johnkchow/821508 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
void Application_Error(object sender, EventArgs e) | |
{ | |
Exception ex = Server.GetLastError(); | |
if (ex.GetType() != typeof(HttpException)) | |
{ | |
if (ex.GetType() == typeof(HttpUnhandledException) && ex.InnerException != null) | |
ex = ex.InnerException; | |
CoreManager.ExceptionService.HandleException(ex); | |
} | |
else if (ex.GetType() == typeof(HttpException)) | |
{ | |
HttpException httpEx = ex as HttpException; | |
if (httpEx != null && httpEx.GetHttpCode() == 404) | |
{ | |
RouteData routeData = new RouteData(); | |
routeData.Values.Add("controller", "Error"); | |
routeData.Values.Add("action", "HttpError404"); | |
routeData.Values.Add("exception", ex); | |
Server.ClearError(); | |
Response.TrySkipIisCustomErrors = true; | |
IController errorController = new ErrorController(); | |
errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData)); | |
} | |
} | |
} | |
//... In the ErrorController file... | |
public class ErrorController : Controller | |
{ | |
public ActionResult HttpError404() | |
{ | |
Response.StatusCode = 404; | |
return View(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment