Created
January 23, 2013 09:17
-
-
Save martinnormark/4603530 to your computer and use it in GitHub Desktop.
Log handled exception in AJAX request to ELMAH
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
using System.Net; | |
using System.Web.Mvc; | |
namespace MyApp.Web.PresentationLogic.ActionFilters | |
{ | |
public class HandleAjaxErrorAttribute : HandleErrorAttribute | |
{ | |
public override void OnException(ExceptionContext filterContext) | |
{ | |
if (!filterContext.RequestContext.HttpContext.Request.IsAjaxRequest()) | |
{ | |
base.OnException(filterContext); | |
return; | |
} | |
else | |
{ | |
if (filterContext.HttpContext.IsDebuggingEnabled) | |
{ | |
return; | |
} | |
filterContext.ExceptionHandled = true; | |
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; | |
filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; | |
filterContext.HttpContext.Response.StatusDescription = filterContext.Exception.Message; | |
Elmah.ErrorSignal.FromCurrentContext().Raise(filterContext.Exception); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment