Last active
August 29, 2015 14:21
-
-
Save tompazourek/6aab5d5192578dfe4bf3 to your computer and use it in GitHub Desktop.
ASP.NET MVC Errors
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
// 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; | |
} |
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
<modules runAllManagedModulesForAllRequests="true"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment