Skip to content

Instantly share code, notes, and snippets.

@tompazourek
Last active August 29, 2015 14:21
Show Gist options
  • Save tompazourek/6aab5d5192578dfe4bf3 to your computer and use it in GitHub Desktop.
Save tompazourek/6aab5d5192578dfe4bf3 to your computer and use it in GitHub Desktop.
ASP.NET MVC Errors
// NOTE: ELMAH logs the errors anyway
protected void Application_Error(object sender, EventArgs e)
{
var exception = Server.GetLastError();
var httpException = exception as HttpException;
if (httpException != null)
{
switch (httpException.GetHttpCode())
{
case 404:
Response.RedirectToRoute(new { controller = "Error", action = "NotFound", path = Request.Path });
break;
}
}
if (!Response.IsRequestBeingRedirected)
{
Response.RedirectToRoute(new { controller = "Error", action = "Index" });
}
// clear the error on server.
Server.ClearError();
// avoid IIS7 getting in the middle
Response.TrySkipIisCustomErrors = true;
}
<modules runAllManagedModulesForAllRequests="true">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment