Last active
August 29, 2015 14:04
-
-
Save abrudtkuhl/8756dc0f329e3700d791 to your computer and use it in GitHub Desktop.
ASP.Net MVC Error Handling
This file contains hidden or 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() | |
{ | |
var unhandledException = Server.GetLastError(); | |
var httpException = unhandledException as HttpException; | |
if (httpException == null) | |
{ | |
var innerException = unhandledException.InnerException; | |
httpException = innerException as HttpException; | |
} | |
if (httpException == null) return; | |
var httpCode = httpException.GetHttpCode(); | |
switch (httpCode) | |
{ | |
case (int)HttpStatusCode.NotFound: | |
Response.Redirect("/Error/NotFound"); | |
break; | |
case (int)HttpStatusCode.BadRequest: | |
Response.Redirect("/Error/BadRequest"); | |
break; | |
case (int)HttpStatusCode.InternalServerError: | |
Response.Redirect("/Error/InternalServerError"); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment