Skip to content

Instantly share code, notes, and snippets.

@abrudtkuhl
Last active August 29, 2015 14:04
Show Gist options
  • Save abrudtkuhl/8756dc0f329e3700d791 to your computer and use it in GitHub Desktop.
Save abrudtkuhl/8756dc0f329e3700d791 to your computer and use it in GitHub Desktop.
ASP.Net MVC Error Handling
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