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
public class ErrorHandlerHttpModule : IHttpModule | |
{ | |
public void Init(HttpApplication context) | |
{ | |
context.Error += Application_Error; | |
} | |
private static void Application_Error(object sender, EventArgs e) | |
{ | |
// Error handling code goes here. |
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
public void Application_Error(object sender, EventArgs e) |
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
filterContext.HttpContext.Response.ClearHeaders(); | |
filterContext.HttpContext.Response.ClearContent(); |
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
filterContext.HttpContext.Response.Clear(); |
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
public class DerivedHandleErrorAttribute : HandleErrorAttribute | |
{ | |
public override void OnException(ExceptionContext filterContext) | |
{ | |
base.OnException(filterContext); | |
if (context.ExceptionHandled) | |
{ | |
// Log filterContext.Exception in some way. | |
} |
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
new HandleErrorAttribute | |
{ | |
View = "SomeView", | |
ExceptionType = typeof (SomeException) | |
} |
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
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | |
{ | |
filters.Add(new HandleErrorAttribute()); | |
} |
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
Response.TrySkipIisCustomErrors = true; |
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
<httpErrors errorMode="Custom" existingResponse="Replace"> | |
<remove statusCode="500" /> | |
<error | |
statusCode="500" | |
path="/MvcErrorHandling/Error/HttpErrors500" | |
responseMode="ExecuteURL" /> | |
</httpErrors> |
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
<system.webServer> | |
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Auto" /> | |
<!-- any other elements --> | |
</system.webServer> |